package StudentScoreManager;
import java.io.EOFException;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.;
public class SSM {
public static void main(String[] args) throws IOException{
MainMenu mainmenu=new MainMenu();
mainmenu.Startmenu();
}
}
class Student implements Serializable{
int stunum;
String stuname;
int score;
Student(int stuno,String stun,int sco){
stunum=stuno;
stuname=stun;
score=sco;
}
public String toString(){
return 学号+stunum+ 姓名+stuname+ 分数+score;
}
}
class StudentList {
ArrayListStudent list = new ArrayListStudent();
Boolean IsEmpty(){
if(!list.isEmpty())
return true;
else{
System.out.print(错误!列表为空!!);
return false;
}
}
void CreatList(){
Scanner scan=new Scanner(System.in);
System.out.println(有几位学生);
int Int();
System.out.println(输入学生学号、姓名和成绩(number name score格式));
for(int i=0;in;i++){
int Int();
String ();
int Int();
Student student=new Student(number,name,score);
list.add(student);
}
}
void OutPut(){
for(Student s list)
System.out.println(s);
}
void NameSearch(String name){
for(Student s list){
if(s.stuname.equals(name))
System.out.println(s);
}
}
void NumberSearch(int number){
for(Student s list){
if(s.stunum==number)
System.out.println(s);
}
}
void Sort(final int n){
ComparatorStudent comparator = new ComparatorStudent(){
public int compare(Student s1, Student s2) {
if(n==4)
return s1.stunum-s2.stunum;
else
return s2.score-s1.score;
}
};
Collections.sort(list,comparator);
for(Student s list)
System.out.println(s);
}
void Save() {
try{
FileOutputStream fs = new );
ObjectOutputStream os = new ObjectOutputStream(fs);
for(Student s list)
os.writeObject(s);
os.close();
}catch(Exception ex){
ex.printStackTrace();
}
System.out.print(保存成功!!);
}
void Load(){
try{
FileInputStream fis = new );
用sort out ObjectInputStream ois = new ObjectInputStream(fis);
while(true){
try{
Student stu =(Student) adObject();
list.add(stu);
}catch (EOFException e) {
ois.close();
break;
}
}
}catch(Exception ex){
ex.printStackTrace();
}
System.out.println(加载成功!!);
}
public void remove() {
veAll(list);
}
}
class MainMenu{
void Startmenu(){
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(7加载);
System.out.println(0退出);
StudentList studentlist=new StudentList();
Scanner scan=new Scanner(System.in);
int Int();
while(true){
switch(a){
case 1
System.out.println(输入学生信息……);
studentlist.CreatList();
studentlist.OutPut();
break;
case 2
System.out.println(由姓名查询……);
if(studentlist.IsEmpty()){
System.out.println(输入名字:);
String ();
studentlist.NameSearch(name);
}
break;
case 3
System.out.println(由学号查询……);
if(studentlist.IsEmpty()){
System.out.println(输入学号:);
int Int();
studentlist.NumberSearch(number);
}
break;
case 4
if(studentlist.IsEmpty()){
System.out.println(由学号排序(升序)……);
studentlist.Sort(4);
}
break;
case 5
if(studentlist.IsEmpty()){
System.out.println(由分数排序(降序)……);
studentlist.Sort(5);
}
break;
case 6
System.out.println(保存……);
studentlist.Save();
break;
case 7
System.out.println(加载……);
ve();
studentlist.Load();
studentlist.OutPut();
break;
case 0
System.out.println(退出……);
it(0);
default
System.out.print(选择错误,请重新选择);
}
Int();
}
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论