package View;
import Domain.Student;
import Service.NameListService;
import Service.TeamException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
public class Teamview {
private NameListService listSvc =new NameListService();
private List<Student> stuList=new ArrayList<>();
public Teamview() {
stuList=listSvc.getAllStudent();
}
public void enterMenu(){
boolean flag=true;
int menu;
Scanner in=new Scanner(System.in);
while(flag){
listAllStudents();
menu=in.nextInt();
switch (menu){
case 1:
addStudent();
break;
case 2:
try {
deleteStudent();
} catch (TeamException e) {
System.out.println("删除失败,原因:"+e.getMessage());
}
break;
case 3:
try {
changeStudent();
} catch (TeamException e) {
System.out.println("修改失败,原因:"+e.getMessage());
}
break;
case 4:
sortStudent();
break;
case 5:
return ;
}
}
}
private void sortStudent() {
System.out.println("请选择排序方式");
System.out.println("1--------->学号");
System.out.println("2--------->总成绩");
Scanner in=new Scanner(System.in);
int choice=in.nextInt();
switch (choice){
case 1:
stuList.sort(Comparator.comparing(Student::getId));
break;
case 2:
stuList.sort(Comparator.comparing(Student::getSumScore).reversed());
break;
}
}
private void changeStudent() throws TeamException {
Scanner in=new Scanner(System.in);
System.out.println("请输入要修改的学生学号");
int id=in.nextInt();
boolean tag=false;
int i;
for (i = 0; i < stuList.size(); i++) {
if(stuList.get(i).getId()==id){
tag=true;
break;
}
}
if(tag==true){
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--------->Java成绩");
int choice=in.nextInt();
switch (choice){
case 1:
System.out.println("请输入修改后的姓名");
String name=in.next();
stuList.get(i).setName(name);
break;
case 2:
System.out.println("请输入修改后的学号");
int Id=in.nextInt();
stuList.get(i).setId(Id);
break;
case 3:
System.out.println("请输入修改后的语文成绩");
double score=in.nextDouble();
stuList.get(i).setChineseScore(score);
break;
case 4:
System.out.println("请输入修改后的数学成绩");
score=in.nextDouble();
stuList.get(i).setMathScore(score);
break;
case 5:
System.out.println("请输入修改后的英语成绩");
score=in.nextDouble();
stuList.get(i).setEnglishScore(score);
break;
case 6:
System.out.println("请输入修改后的Java成绩");
score=in.nextDouble();
stuList.get(i).setJavaScore(score);
break;
}
System.out.println("修改成功");
enterExit();
return;
}
throw new TeamException("未找到学生信息");
}
private void deleteStudent() throws TeamException {
Scanner in=new Scanner(System.in);
System.out.println("请输入要删除的学生学号");
int id=in.nextInt();
for (int i = 0; i < stuList.size(); i++) {
if(stuList.get(i).getId()==id){
stuList.remove(i);
System.out.println("删除成功");
enterExit();
return;
}
}
throw new TeamException("未找到该学生信息");
}
public void listAllStudents(){
System.out.println("----------------------------------学生成绩管理系统--------------------------------");
System.out.println("姓名\t"+"学号\t"+"语文成绩\t"+"数学成绩\t"+"英语成绩\t"+"Java成绩\t"+"平均分\t"+"总成绩\t");
for(int i=0;i<stuList.size();i++){
String name= stuList.get(i).getName();
int id=stuList.get(i).getId();
double ChineseScore=stuList.get(i).getChineseScore();
double MathScore=stuList.get(i).getMathScore();
double EnglishScore=stuList.get(i).getEnglishScore();
double JavaScore=stuList.get(i).getJavaScore();
double averageScore=stuList.get(i).getAverageScore();
double sumScore=stuList.get(i).getSumScore();
System.out.println(name+"\t"+id+"\t\t"+ChineseScore+"\t"+MathScore+"\t"+EnglishScore+"\t"+JavaScore+"\t\t"
+averageScore+"\t"+sumScore);
}
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--------->退出系统");
}
public void addStudent(){
Scanner in=new Scanner(System.in);
System.out.println("请输入学生姓名");
String name=in.next();
System.out.println("请输入学生学号");
int id=in.nextInt();
System.out.println("请输入学生语文成绩");
double chineseScore=in.nextDouble();
System.out.println("请输入学生数学成绩");
double mathScore=in.nextDouble();
System.out.println("请输入学生英语成绩");
double englishScore=in.nextDouble();
System.out.println("请输入学生Java成绩");
double javaScore=in.nextDouble();
Student stu=new Student(name,id,chineseScore,mathScore,englishScore,javaScore);
listSvc.addStudent(stu);
System.out.println("--------------------添加成功--------------------");
enterExit();
}
public void enterExit(){
System.out.println("请按任意键返回.......");
Scanner in=new Scanner(System.in);
String c=in.next();
}
public static void main(String[] args) {
Teamview view =new Teamview();
view.enterMenu();
}
}
评论0