期末项目。。

代码

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package Study;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Scanner;

public class StudentManager {
public StudentManager() {
}

public static void main(String[] args) {
    ArrayList array = new ArrayList();

    while(true) {
        System.out.println("--------欢迎来到学生管理系统--------");
        System.out.println("1 添加学生");
        System.out.println("2 删除学生");
        System.out.println("3 修改学生");
        System.out.println("4 查看所有学生");
        System.out.println("5 退出");
        System.out.println("请输入您的选择:");
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        byte var5 = -1;
        switch(line.hashCode()) {
        case 49:
            if (line.equals("1")) {
                var5 = 0;
            }
            break;
        case 50:
            if (line.equals("2")) {
                var5 = 1;
            }
            break;
        case 51:
            if (line.equals("3")) {
                var5 = 2;
            }
            break;
        case 52:
            if (line.equals("4")) {
                var5 = 3;
            }
            break;
        case 53:
            if (line.equals("5")) {
                var5 = 4;
            }
        }

        switch(var5) {
        case 0:
            addStudent(array);
            break;
        case 1:
            deleteStudent(array);
            break;
        case 2:
            updateStudent(array);
            break;
        case 3:
            findAllStudent(array);
            break;
        case 4:
            System.out.println("谢谢使用");
            System.exit(0);
        }
    }
}

public static void addStudent(ArrayList<Student> array) {
    Scanner sc = new Scanner(System.in);

    while(true) {
        System.out.println("请输入学生学号:");
        String sid = sc.nextLine();
        boolean flag = isUsed(array, sid);
        if (!flag) {
            System.out.println("请输入学生姓名:");
            String name = sc.nextLine();
            System.out.println("请输入学生年龄:");
            String age = sc.nextLine();
            System.out.println("请输入学生居住地:");
            String address = sc.nextLine();
            Student s = new Student();
            s.setSid(sid);
            s.setName(name);
            s.setAge(age);
            s.setAddress(address);
            array.add(s);
            System.out.println("添加学生成功");
            return;
        }

        System.out.println("你输入的学号已经被使用,请重新输入");
    }
}

public static boolean isUsed(ArrayList<Student> array, String sid) {
    boolean flag = false;

    for(int i = 0; i < array.size(); ++i) {
        Student s = (Student)array.get(i);
        if (s.getSid().equals(sid)) {
            flag = true;
            break;
        }
    }

    return flag;
}

public static void findAllStudent(ArrayList<Student> array) {
    if (array.size() == 0) {
        System.out.println("无信息,请先添加信息再查询");
    } else {
        System.out.println("学号\t\t\t\t姓名\t\t年龄\t\t居住地");

        for(int i = 0; i < array.size(); ++i) {
            Student s = (Student)array.get(i);
            PrintStream var10000 = System.out;
            String var10001 = s.getSid();
            var10000.println(var10001 + "\t" + s.getName() + "\t" + s.getAge() + "岁\t" + s.getAddress());
        }
    }

}

public static void deleteStudent(ArrayList<Student> array) {
    Scanner sc = new Scanner(System.in);
    System.out.println("请输入你要删除的学生学号:");
    String sid = sc.nextLine();
    int index = -1;

    for(int i = 0; i < array.size(); ++i) {
        Student s = (Student)array.get(i);
        if (s.getSid().equals(sid)) {
            index = i;
            break;
        }
    }

    if (index == -1) {
        System.out.println("该信息不存在,请重新输入");
    } else {
        array.remove(index);
        System.out.println("删除学生成功");
    }

}

public static void updateStudent(ArrayList<Student> array) {
    Scanner sc = new Scanner(System.in);
    System.out.println("请输入你要修改的学生学号:");
    String sid = sc.nextLine();
    int index = -1;

    for(int i = 0; i < array.size(); ++i) {
        Student student = (Student)array.get(i);
        if (student.getSid().equals(sid)) {
            index = i;
            break;
        }
    }

    if (index == -1) {
        System.out.println("不存在要修改的学生学号,请重新输入");
    } else {
        System.out.println("请输入学生新的姓名:");
        String name = sc.nextLine();
        System.out.println("请输入学生新的年龄:");
        String age = sc.nextLine();
        System.out.println("请输入学生新的居住地:");
        String address = sc.nextLine();
        Student s = new Student();
        s.setSid(sid);
        s.setName(name);
        s.setAge(age);
        s.setAddress(address);
        array.set(index, s);
        System.out.println("修改学生信息成功");
    }

}

}
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值