Java练习学生信息管理系统,第一次写,对于类要怎么弄,函数要干嘛,main方法静态不能用非静态的等等很是烦恼了好大一阵。
幸好ArrayList做参数时,是引用传递。。。C++用&就可以引用传递,Java呢?
1 package Student; 2 3 public class Student 4 { 5 private String stunumber; 6 private String name; 7 private int age; 8 private boolean sex;//man=false,woman=true 9 private Double score;10 Student ()11 {12 stunumber="";13 name="";14 age=0;15 sex=false;16 score=0.0;17 }18 Student (String a,String b,int c,boolean d,Double e)19 {20 stunumber=a;21 name=b;22 age=c;23 sex=d;24 score=e;25 }26 public void set_stunumber(String str)27 {28 stunumber=str;29 }30 public void set_name(String str)31 {32 name=str;33 }34 public void set_age(int n)35 {36 age=n;37 }38 public void set_sex(boolean bool)39 {40 sex=bool;41 }42 public void set_score(Double n)43 {44 score=n;45 }46 public String get_stunumber()47 {48 return stunumber;49 }50 public String get_name()51 {52 return name;53 }54 public int get_age()55 {56 return age;57 }58 public boolean get_sex()59 {60 return sex;61 }62 public Double get_score()63 {64 return score;65 }66 67 }
1 package Student; 2 import java.util.Scanner; 3 import java.util.ArrayList; 4 public class StudentManager 5 { 6 public static void main(String[] args) 7 { 8 Scanner input=new Scanner(System.in); 9 ArrayListstu=new ArrayList (); 10 int select=1; 11 for(;;) 12 { 13 face(); 14 do 15 { 16 select=input.nextInt(); 17 }while(select<1||select>5); 18 switch(select) 19 { 20 case 1:showStudent(stu);break; 21 case 2:addStudent(stu);break; 22 case 3:deleteStudent(stu);break; 23 case 4:updateStudent(stu);break; 24 case 5:selectStudent(stu);break; 25 } 26 } 27 } 28 private static void addStudent(ArrayList stu) 29 { 30 Student stu0=new Student(); 31 String a, b,f; 32 int c; 33 boolean d=false,j=true; 34 Double e; 35 36 Scanner input=new Scanner(System.in); 37 System.out.println("请依次输入:学号、姓名、年龄、性别、成绩"); 38 a=input.next(); 39 b=input.next(); 40 c=input.nextInt(); 41 f=input.next(); 42 e=input.nextDouble(); 43 if(stu.size()!=0) 44 { 45 for(int i=0;i stu) 76 { 77 boolean f=false; 78 String str; 79 System.out.println("请输入要删除的学生的学号:"); 80 Scanner input=new Scanner(System.in); 81 str=input.next(); 82 for(int i=0;i stu) 97 { 98 Student stu0; 99 String a, b,f;100 int c,num=0;101 boolean d,j=true;102 Double e;103 Scanner input=new Scanner(System.in);104 System.out.println("请输入待修改学生学号:");105 a=input.next();106 if(stu.size()!=0)107 {108 for(int i=0;i stu)156 {157 boolean j=true;//默认无重复158 int num=0;159 String s;160 Scanner input=new Scanner(System.in);161 String str;162 System.out.println("请输入学号:");163 str=input.next();164 if(stu.size()!=0)165 {166 for(int i=0;i stu)209 {210 String s;211 for(int i=0;i