package StudentMange;
Course类
package StudentMange. Student;
public class Course {
private int math;
private int English;
private int perfectCourse;
public Course ( ) {
}
public Course ( int math, int english, int perfectCourse) {
this . math = math;
English = english;
this . perfectCourse = perfectCourse;
}
public int getMath ( ) {
return math;
}
public void setMath ( int math) {
this . math = math;
}
public int getEnglish ( ) {
return English;
}
public void setEnglish ( int english) {
English = english;
}
public int getPerfectCourse ( ) {
return perfectCourse;
}
public void setPerfectCourse ( int perfectCourse) {
this . perfectCourse = perfectCourse;
}
}
Student类
package StudentMange. Student;
public class Student {
private int no;
private String name;
private int age;
private int courseCount;
Course cou;
public Course getCou ( ) {
return cou;
}
public void setCou ( Course cou) {
this . cou = cou;
}
public Student ( ) {
}
public Student ( int no, String name, int age, int courseCount, Course cou) {
this . no = no;
this . name = name;
this . age = age;
this . courseCount = courseCount;
this . cou = cou;
}
public int getNo ( ) {
return no;
}
public void setNo ( int no) {
this . no = no;
}
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 int getCourseCount ( ) {
return courseCount;
}
public void setCourseCount ( int courseCount) {
this . courseCount = courseCount;
}
}
package StudentMange;
import StudentMange. Student. Course;
import StudentMange. Student. Student;
import java. util. *;
public class Main {
static List< Student> students= new ArrayList ( ) ;
static Scanner scanner= new Scanner ( System. in) ;
public static void main ( String[ ] args) {
students. add ( new Student ( 2 , "全兴涛" , 20 , 10 , new Course ( 89 , 99 , 100 ) ) ) ;
students. add ( new Student ( 1 , "邱晨光" , 20 , 9 , new Course ( 81 , 75 , 120 ) ) ) ;
students. add ( new Student ( 3 , "黄英龙" , 20 , 8 , new Course ( 82 , 94 , 87 ) ) ) ;
System. out. println ( "欢迎使用学生成绩管理系统" ) ;
while ( true ) {
System. out. println ( "****************************************************" ) ;
System. out. println ( "* 1--显示 2--追加 3--查找 4--删除 *" ) ;
System. out. println ( "* 5--修改 6--统计 7--排序 8--查询成绩 *" ) ;
System. out. println ( "*************************************************** *" ) ;
System. out. println ( "选择菜单序号(1--8):" ) ;
int choice= scanner. nextInt ( ) ;
switch ( choice) {
case 1 :
show ( ) ;
break ;
case 2 :
System. out. print ( "请输入追加内容" ) ;
addStu ( ) ;
show ( ) ;
break ;
case 3 :
System. out. print ( "请输入你想要查找的学号:" ) ;
search ( ) ;
break ;
case 4 :
System. out. print ( "请输入你要删除的学号:" ) ;
delete ( ) ;
show ( ) ;
break ;
case 5 :
System. out. print ( "请输入你想修改的学号:" ) ;
modify ( ) ;
show ( ) ;
break ;
case 6 :
System. out. println ( "一共有" + Main. count ( ) + "人" ) ;
show ( ) ;
break ;
case 7 :
sort ( ) ;
show ( ) ;
break ;
case 8 :
searchScore ( ) ;
break ;
}
}
}
public static void searchScore ( ) {
System. out. println ( "请输入您的学号:" ) ;
int no= scanner. nextInt ( ) ;
Iterator< Student> it= students. iterator ( ) ;
while ( it. hasNext ( ) ) {
Student s= it. next ( ) ;
if ( s. getNo ( ) == no) {
System. out. println ( "请输入你想要查询的科目:" ) ;
String course= scanner. next ( ) ;
if ( course. equals ( "math" ) ) {
System. out. println ( "您的数学成绩是: " + s. getCou ( ) . getMath ( ) ) ;
return ;
}
if ( course. equals ( "english" ) ) {
System. out. println ( "您的数学成绩是:" + s. getCou ( ) . getEnglish ( ) ) ;
return ;
}
if ( course. equals ( "perfectCourse" ) ) {
System. out. println ( "您的专业课成绩是:" + s. getCou ( ) . getPerfectCourse ( ) ) ;
return ;
}
return ;
}
}
System. out. println ( "您输入的学号不存在!!!!" ) ;
}
public static void sort ( ) {
Collections. sort ( students, new Comparator < Student> ( ) {
@Override
public int compare ( Student o1, Student o2) {
if ( o1. getNo ( ) > o2. getNo ( ) ) {
return 1 ;
}
else
return - 1 ;
}
} ) ;
}
public static int count ( ) {
return students. size ( ) ;
}
public static void modify ( ) {
int no= scanner. nextInt ( ) ;
Iterator< Student> it= students. iterator ( ) ;
while ( it. hasNext ( ) ) {
Student s = it. next ( ) ;
if ( s. getNo ( ) == no) {
System. out. println ( "该学生学号为:" + s. getNo ( ) ) ;
System. out. println ( "你将学号改为:" ) ;
s. setNo ( scanner. nextInt ( ) ) ;
System. out. println ( "该学生姓名为:" + s. getName ( ) ) ;
System. out. println ( "你将姓名改为:" ) ;
s. setName ( scanner. next ( ) ) ;
System. out. println ( "该学生年龄为:" + s. getAge ( ) ) ;
System. out. println ( "你将年龄改为:" ) ;
s. setAge ( scanner. nextInt ( ) ) ;
System. out. println ( "该学生选课总数为:" + s. getCourseCount ( ) ) ;
System. out. println ( "你将选课总数改为:" ) ;
s. setCourseCount ( scanner. nextInt ( ) ) ;
break ;
}
}
}
public static void delete ( ) {
int no= scanner. nextInt ( ) ;
Iterator< Student> it= students. iterator ( ) ;
while ( it. hasNext ( ) ) {
Student s = it. next ( ) ;
if ( s. getNo ( ) == no) {
it. remove ( ) ;
}
break ;
}
}
public static void search ( ) {
int no= scanner. nextInt ( ) ;
Iterator< Student> it= students. iterator ( ) ;
while ( it. hasNext ( ) ) {
Student s= it. next ( ) ;
if ( s. getNo ( ) == no) {
System. out. println ( "该学号的姓名是:" + s. getName ( ) + "\n" + "该学号的年龄是:" + s. getAge ( ) + "\n" + "该学号的选课总数是:" + s. getCourseCount ( ) ) ;
}
}
}
public static void addStu ( ) {
System. out. println ( "请输入你想添加的人数:" ) ;
int i= 0 ;
int count= scanner. nextInt ( ) ;
while ( i< count) {
System. out. print ( "请输入姓名:" ) ;
String name = scanner. next ( ) ;
System. out. print ( "请输入学号:" ) ;
int no = scanner. nextInt ( ) ;
System. out. print ( "请输入年龄:" ) ;
int age = scanner. nextInt ( ) ;
System. out. print ( "请输入选课总数:" ) ;
int courseCount = scanner. nextInt ( ) ;
System. out. print ( "请输入数学成绩:" ) ;
int math = scanner. nextInt ( ) ;
System. out. print ( "请输入英语成绩:" ) ;
int english = scanner. nextInt ( ) ;
System. out. print ( "请输入专业课成绩:" ) ;
int perfect = scanner. nextInt ( ) ;
Course c = new Course ( math, english, perfect) ;
Student NEW = new Student ( no, name, age, courseCount, c) ;
students. add ( NEW) ;
System. out. println ( "追加成功!!!!!!" ) ;
i++ ;
}
}
public static void show ( ) {
Iterator< Student> it= students. iterator ( ) ;
while ( it. hasNext ( ) ) {
Student s= it. next ( ) ;
System. out. print ( "学号:" + s. getNo ( ) + ";" ) ;
System. out. print ( "姓名:" + s. getName ( ) + ";" ) ;
System. out. print ( "年龄:" + s. getAge ( ) + ";" ) ;
System. out. println ( "选课总数:" + s. getCourseCount ( ) + ";" ) ;
System. out. print ( "英语:" + s. getCou ( ) . getEnglish ( ) + " " ) ;
System. out. print ( "数学:" + s. getCou ( ) . getMath ( ) + " " ) ;
System. out. println ( "专业课: :" + s. getCou ( ) . getPerfectCourse ( ) + " " ) ;
}
}
}