目录
前言:
源码:
前言:
我对于集合的理解,感觉就类似于顺序表这样的数据结构,然后他存储的数据不能是基本类型,如果要用也只能用对应基本数据的包装类。
对于集合有很多方法,我的建议就是去api里面文档查看就行,没必要可以去背。
源码:
哈哈哈,这个系统太经典了,拿来练习语法再合适不过了~
实体类:
public class StudentInfor {private String id;private String name;private int age;private String sex;private int MathScore;private int ChineseSocre;private int EnglishScore;private int arrSocre;public String getId() {return id;}public void setId(String id) {this.id = id;}public StudentInfor() {}public StudentInfor(String id, String name, int age, String sex, int mathScore, int chineseSocre, int englishScore) {this.id = id;this.name = name;this.age = age;this.sex = sex;MathScore = mathScore;ChineseSocre = chineseSocre;EnglishScore = englishScore;arrSocre=mathScore+chineseSocre+englishScore;}public int getArrSocre() {return arrSocre;}public void setArrSocre() {arrSocre=MathScore+EnglishScore+ChineseSocre;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}public String getSex() {return sex;}public void setSex(String sex) {this.sex = sex;}public int getMathScore() {return MathScore;}public void setMathScore(int mathScore) {MathScore = mathScore;}public int getChineseSocre() {return ChineseSocre;}public void setChineseSocre(int chineseSocre) {ChineseSocre = chineseSocre;}public int getEnglishScore() {return EnglishScore;}public void setEnglishScore(int englishScore) {EnglishScore = englishScore;}
}
方法类:
import java.util.ArrayList;
import java.util.Scanner;public class System_Z {private static void SetInfor(ArrayList<StudentInfor> list){StudentInfor student = new StudentInfor();Scanner sc=new Scanner(System.in);System.out.println("请输入姓名->");student.setName(sc.next());System.out.println("请输入学号->");String id=sc.next();for (int i = 0; i < list.size(); i++) {while (id.equals(list.get(i).getId())) {System.out.println("已存在该学号!");System.out.println("请重新输入");id = sc.next();}}student.setId(id);System.out.println("请输入年龄->");student.setAge(sc.nextInt());System.out.println("请输入性别->");student.setSex(sc.next());System.out.println("请输入语文成绩");student.setChineseSocre(sc.nextInt());System.out.println("请输入数学成绩");student.setMathScore(sc.nextInt());System.out.println("请输入英语成绩");student.setEnglishScore(sc.nextInt());student.setArrSocre();list.add(student);}private static void PrintAllStudent(ArrayList<StudentInfor>list){System.out.println("姓名 id 年龄 性别 语文 数学 英语 总分");for (int i = 0; i < list.size(); i++) {
/* System.out.println(list.get(i).getName()+" "+list.get(i).getId()+" "+list.get(i).getAge()+" "+list.get(i).getSex()+" "+list.get(i).getChineseSocre()+"\t"+list.get(i).getMathScore()+" "+list.get(i).getEnglishScore()+" "+list.get(i).getArrSocre());*/System.out.printf("%-5s%-13s%-6d%-6s%-6d%-6d%-6d%-6d\n",list.get(i).getName(),list.get(i).getId(),list.get(i).getAge(),list.get(i).getSex(),list.get(i).getChineseSocre(),list.get(i).getMathScore(),list.get(i).getEnglishScore(),list.get(i).getArrSocre());}}private static void Print(){System.out.println("1.录入学生信息");System.out.println("2.输入id查看学生信息");System.out.println("3.输入学生姓名查看学生信息");System.out.println("4.输入学号修改学生信息");System.out.println("5.打印全部学生信息");System.out.println("6.输入学号删除学生信息");System.out.println("0.退出");}private static void FindByName(ArrayList<StudentInfor> list ){System.out.println("请输入要查的学生姓名");Scanner sc=new Scanner(System.in);String name=sc.next();int n=0;for (int i = 0; i < list.size(); i++) {if(name.equals(list.get(i).getName())){n=1;System.out.println("学生姓名:"+list.get(i).getName());System.out.println("学生id:"+list.get(i).getId());System.out.println("学生年龄:"+list.get(i).getAge());System.out.println("学生性别:"+list.get(i).getSex());System.out.println("语文成绩:"+list.get(i).getChineseSocre());System.out.println("数学成绩:"+list.get(i).getMathScore());System.out.println("英语成绩:"+list.get(i).getEnglishScore());System.out.println("总成绩:"+list.get(i).getArrSocre());System.out.println();}}if(n==0){System.out.println("没找到喵");System.out.println();}}private static void FindByID(ArrayList<StudentInfor> list ){System.out.println("请输入要查的学号");Scanner sc=new Scanner(System.in);String id=sc.next();for (int i = 0; i < list.size(); i++) {if(id.equals(list.get(i).getId())){System.out.println("学生姓名:"+list.get(i).getName());System.out.println("学生id:"+list.get(i).getId());System.out.println("学生年龄:"+list.get(i).getAge());System.out.println("学生性别:"+list.get(i).getSex());System.out.println("语文成绩:"+list.get(i).getChineseSocre());System.out.println("数学成绩:"+list.get(i).getMathScore());System.out.println("英语成绩:"+list.get(i).getEnglishScore());System.out.println("总成绩:"+list.get(i).getArrSocre());System.out.println();return ;}}System.out.println("没找到喵");System.out.println();}private static void RemakeByname(ArrayList<StudentInfor>list ){System.out.println("请输入要修改学生的学号");Scanner sc=new Scanner(System.in);String id=sc.next();for (int i = 0; i < list.size(); i++) {if(id.equals(list.get(i).getId())){System.out.println("请输入姓名->");list.get(i).setName(sc.next());System.out.println("请输入学号->");list.get(i).setName(sc.next());System.out.println("请输入年龄->");list.get(i).setAge(sc.nextInt());System.out.println("请输入性别->");list.get(i).setSex(sc.next());System.out.println("请输入语文成绩");list.get(i).setChineseSocre(sc.nextInt());System.out.println("请输入数学成绩");list.get(i).setMathScore(sc.nextInt());System.out.println("请输入英语成绩");list.get(i).setEnglishScore(sc.nextInt());list.get(i).setArrSocre();return ;}}}private static void DeleteByid(ArrayList<StudentInfor>list){System.out.println("请输入要查的学号");Scanner sc=new Scanner(System.in);String id=sc.next();for (int i = 0; i < list.size(); i++) {if(id.equals(list.get(i).getId())){list.remove(i);System.out.println("删除成功!");return ;}}System.out.println("没有查找到该学生信息喵~");}private static void main(String[] args) {ArrayList<StudentInfor> list=new ArrayList<>();StudentInfor s1=new StudentInfor("2023211661","牢大",24,"男",59,89,100);StudentInfor s2=new StudentInfor("2023211662","蔡徐坤",25,"男",88,81,66);list.add(s1);list.add(s2);System.out.println("-------欢迎使用学生信息管理系统------");Scanner sc=new Scanner(System.in);int choice=100;while(choice!=0){Print();choice = sc.nextInt();switch(choice){case 1:SetInfor(list);break;case 2:FindByID(list);break;case 3:FindByName(list);break;case 4:RemakeByname(list);break;case 5:PrintAllStudent(list);System.out.println();break;case 6:DeleteByid(list);break;case 0:System.out.println("欢迎下次使用喵~");break;default:System.out.println("选择错误请重新选择");System.out.println();break;}}}}