java学生管理系统项目(面向接口思想)

一开始自己写的学生管理系统被老师说了一通,说我写的学生管理系统是面向过程的,是c语言的逻辑,学java就应该用java的思想。

这个是我一开始写的面向过程的方法也就是错误示例:

package StudentManager;

import java.util.ArrayList;
import java.util.Scanner;

public class StudentManager {
    public static void main(String[] args) {
        ArrayList<Student> array = new ArrayList<>();
        Scanner sc = new Scanner(System.in);
        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.退出学生管理系统");

            String line = sc.nextLine();
            switch (line) {
                case "1":
                    addStudent(array);
                    break;
                case "2":
                    deleteStudent(array);
                    break;
                case "3":
                    updateStudent(array);
                    break;
                case "4":
                    findStudent(array);
                    break;
                case "5":
                    System.exit(0);
                    System.out.println("感谢使用");
                    break;
                default:
                    throw new IllegalStateException("Unexpected value: " + line);
            }
        }
    }

    private static void findStudent(ArrayList<Student> array) {
        if (array.size() == 0) {
            System.out.println("没有内容,请先添加");
        } else {
            System.out.println("姓名" + "\t" + "年龄" + "\t" + "学号" + "\t" + "地址");
            for (int i = 0; i < array.size(); i++) {
                Student s = array.get(i);
                System.out.println(s.getName() + "\t" + s.getAge() + "\t" + s.getSid() + "\t" + s.getAddress());
            }
        }
    }

    private static void updateStudent(ArrayList<Student> array) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            System.out.println("请输入要修改的学生学号");
            String sid = sc.nextLine();
            if (array.size()==0){
                System.out.println("系统中没有内容,修改失败");
                break;
            }else {
                int index = -1;
                for (int i = 0; i < array.size(); i++) {
                    Student s = array.get(i);
                    if (s.getSid().equals(sid)) {
                        index = i
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值