com.qf.project.mnue
主页面:
package com.qf.project.mnue;
import java.math.MathContext;
import java.util.Random;
import java.util.Scanner;
import com.qf.project.Service.StudentService;
import com.qf.project.StudentSystem.Student;
public class StudentMnue {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
StudentService ss = new StudentService();
// for (int i = 0; i < 5; i++) {
// String name = "阿杰"+i;
// int age = new Random().nextInt(30);
// char sex = '男';
// String className = "11";
// double javaScore = Math.random()*100;
// double htmlScore = Math.random()*100;
// double pythonScore = Math.random()*100;
// Student stu = new Student(name,age,sex,className,javaScore,htmlScore,pythonScore);
// ss.addStudent(stu);
// }
int nums=0;
do{
System.out.println("欢迎来到学院管理系统");
System.out.println("1.查看所有学员");
System.out.println("2.新增学员");
System.out.println("3.查询指定ID的学员信息");
System.out.println("4.根据ID删除学员");
System.out.println("5.根据ID修改学员信息");
System.out.println("6.根据班级名称查询学员");
System.out.println("7.根据姓名(姓/名)查询学员");
System.out.println("8.根据需求排序学员信息");
System.out.println("9.根据需求展示符合条件的学员信息");
System.out.println("0.退出");
System.out.println("请选择:");
nums = sc.nextInt();
switch (nums) {
case 1:
ss.show();
break;
case 2:
ss.addStudent();
break;
case 3:
ss.getStuByID();
break;
case 4:
ss.removeStuByID();
break;
case 5:
ss.modifyByID();
break;
case 6:
ss.getStuByClassName();
break;
case 7:
ss.lastName();
break;
case 8:
ss.stuSort();
break;
case 9:
ss.stuSortPlus();
break;
case 0:
System.out.println("资源正在保存。。。");
ss.output();
return;
default:
break;
}
}while(true);
}
}
com.qf.project.Service
服务区:
package com.qf.project.Service;
import java.util.Scanner;
import com.qf.project.StudentSystem.Student;
import com.qf.project.manager.StudentManager;
public class StudentService {
private StudentManager sdm = null;
Scanner sc = new Scanner(System.in);
public StudentService(){
sdm = new StudentManager();
}
/**
* 查询所有学生对象
*/
public void show(){
sdm.getAll();
}
/**
* 信息初始化
* @param stu
*/
public void addStudent(Student stu){
sdm.add(stu);
}
/**
* 注册学生信息
* 让用户存入信息,并判断信息
*/
public void addStudent(){
System.out.println("请输入姓名:");
String name = sc.next();
int age;
do{
System.out.println("请输入年龄:");
age = sc.nextInt();
}while(age < 0 || age > 123);
char sex;
do{
System.out.println("请输入性别:");
sex = sc.next().charAt(0);
}while(sex != '男' && sex != '女');
System.out.println("请输入班级号:");
String className = sc.next();
System.out.println("请输入java成绩(若没有输入0):");
double javaScore = sc.nextDouble();
System.out.println("请输入html成绩(若没有输入0):");
double htmlScore = sc.nextDouble();
System.out.println("请输入python成绩(若没有输入0):");
double pythonScore = sc.nextDouble();
Student stu = new Student(name,age,sex,className,javaScore,htmlScore,pythonScore);
boolean boo = sdm.add(stu);
if(boo == true){
System.out.println("存入成功");
System.out.println("您存入的学生信息为:" + stu);
}
else{
System.out.println("存入失败");
}
}
/**
* 通过学生的学号来查询学生的信息
*/
public void getStuByID(){
int id = checkID();
Student o = sdm.get(id);
if(o != null){
System.out.println("学生信息为:");
System.out.println(o);
}else{
System.out.println("没用此学号的学生");
}
}
/**
* 通过学号来删除学生
*/
public void removeStuByID(){
int id = checkID();
Student stu = sdm.remove(id);
if(stu != null){
System.out.println("删除成功");
System.out.println("被删除的学生为" + stu);
}else{
System.out.println("删除失败");
}
}
/**
* 通过学号来修改学生信息
*/
public void modifyByID(){
int id = checkID();
Student stu = sdm.get(id);
if(stu != null){
int nums;
do{
System.out.println("学生信息为 " + stu);
System.out.println("请输入想要修改的操作:");
System.out.println("1