标签:scan tcl default 通信 ati 删除 管理系 package mic
此学生管理系统利用了集合ArrayList实现了对学生的增删改查;利用数组中的方法实现分数排序;运用String类的equals实现登录功能的字符串比较。
管理员类:
package data; public class Manger { private String Manname; private String Manpassword; public Manger(String Manname, String Manpassword) { this.Manname = Manname; this.Manpassword = Manpassword; } public String getManname() { return Manname; } public void setManname(String manname) { Manname = manname; } public String getManpassword() { return Manpassword; } public void setManpassword(String manpassword) { Manpassword = manpassword; } @Override public String toString() { return "Manger [Manname=" + Manname + ", Manpassword=" + Manpassword + "]"; } }
学生类:
package data; public class Student { private String name; private String stuno; private String classno; private double point; int age; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getStuno() { return stuno; } public void setStuno(String stuno) { this.stuno = stuno; } public String getClassno() { return classno; } public void setClassno(String classno) { this.classno = classno; } public double getPoint() { return point; } public void setPoint(double point) { this.point = point; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } @Override public String toString() { return "Student [name=" + name + ", stuno=" + stuno + ", classno=" + classno + ", point=" + point + ", age=" + age + "]"; } }
方法类:
package Way; import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; import data.Student; import data.Manger; public class Stuway { ArrayList<Student> array = new ArrayList<Student>(); // ******************************登录************************ public void mainMenu() { System.out.println(); 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("6:退出"); System.out.println("请您输入要操作的功能序号:"); } // ***************************功能选择********************* public int chooseFunction() { Scanner sc = new Scanner(System.in); return sc.nextInt(); } // ****************************信息初始化************************* public void init(ArrayList<Student> array) { Student s1 = new Student(); s1.setName("张彬彬"); s1.setStuno("20171509"); s1.setClassno("计科191"); s1.setPoint(345.0); s1.setAge(23); array.add(s1); Student s2 = new Student(); s2.setName("刘冰冰"); s2.setStuno("20181234"); s2.setClassno("通信181"); s2.setPoint(567); s2.setAge(20); array.add(s2); Student s3 = new Student(); s3.setName("张明敏"); s3.setStuno("20181904"); s3.setClassno("计科191"); s3.setPoint(432); s3.setAge(13); array.add(s3); } // ***************************学生信息显示************************** public void showStudents(ArrayList<Student> array) { for (int i = 0; i < array.size(); i++) { Student s = array.get(i); System.out.println(s);// 运行的是类中的toString } } // **************************增加学生信息************************** public void addStudents(ArrayList<Student> array) { System.out.println("请输入要添加的学生的信息"); Scanner sc = new Scanner(System.in); System.out.println("请输入学生的姓名:"); String name = sc.nextLine(); System.out.println("请输入学生的学号"); String stuno = sc.next(); System.out.println("请输入学生的班级"); String classno = sc.next(); System.out.println("请输入学生的分数"); double point = sc.nextDouble(); System.out.println("请输入学生的年龄"); int age = sc.nextInt(); Student s = new Student(); s.setName(name); s.setStuno(stuno); s.setClassno(classno); s.setPoint(point); s.setAge(age); array.add(s); System.out.println("添加学生信息成功"); } // ****************************删除学生信息*********************** public void delectStudents(ArrayList<Student> array) { System.out.println("选择的是删除功能"); System.out.println("请输入学生的学号"); Scanner sc = new Scanner(System.in); String stuno = sc.next(); for (int i = 0; i < array.size(); i++) {// 遍历集合 Student s = array.get(i); if (s.getStuno().equals(stuno)) { array.remove(i); // 集合的方法remove实现 System.out.println("删除成功"); return; } } System.out.println("你输入的编号不存在"); } // ****************************修改学生信息************************ public void updataStudents(ArrayList<Student> array) { System.out.println("选择的是修改功能"); System.out.println("请输入学生的的学号"); Scanner sc = new Scanner(System.in); String stuno = sc.next(); for (int i = 0; i < array.size(); i++) { Student s = array.get(i); if (s.getStuno().equals(stuno)) { System.out.println("输入新的学生姓名"); s.setStuno(sc.next()); System.out.println("输入新的学生学号"); s.setName(sc.next()); System.out.println("输入新的学生班级"); s.setClassno(sc.nextLine()); System.out.println("输入新的学生分数"); s.setPoint(sc.nextDouble()); System.out.println("输入新的学生年龄"); s.setAge(sc.nextInt()); System.out.println("学生信息修改成功"); return; } } } // *****************************分数排序*********************** public void scoreSort(ArrayList<Student> array) { double[] score = new double[10]; System.out.println("选择的是排序功能"); for (int i = 0; i < array.size(); i++) { Student s = array.get(i); score[i] = s.getPoint(); Arrays.sort(score); } for (int j = 0; j < score.length; j++) { for (int i = 0; i < array.size(); i++) { if (score[j] == array.get(i).getPoint()){ System.out.println(array.get(i)); } } } } // ***************************用户登录************************ public boolean Log() { while (true) { Manger Man = new Manger("manger", "123"); System.out.println("***********欢迎进入学生管理系统**********"); System.out.println("请输入用户名");// manger Scanner sc = new Scanner(System.in); String manger = sc.nextLine(); System.out.println("请输入密码"); String password = sc.next(); if ((Man.getManname().equals(manger)) && (Man.getManpassword().equals(password))) { System.out.println("登陆成功"); return true; } else { System.out.println("登陆失败"); return false; } } } }
测试类:
package main; import java.util.ArrayList; import Way.Stuway; import data.Student; public class Test { public static void main(String[] args) { ArrayList<Student> array = new ArrayList<Student>(); Stuway way = new Stuway(); way.init(array); boolean a=way.Log(); while(a){ way.mainMenu(); int choose = way.chooseFunction(); switch (choose) { case 1: way.showStudents(array); break; case 2: way.addStudents(array); break; case 3: way.delectStudents(array); break; case 4: way.updataStudents(array); break; case 5: way.scoreSort(array); break; default: System.out.println("输入有误"); break; } } } }
运行结果:
标签:scan tcl default 通信 ati 删除 管理系 package mic
原文地址:https://www.cnblogs.com/zhai1997/p/11393356.html