package xuesheng;
import java.util.List;
import java.util.Scanner;
import java.util.TreeSet;
public class Test {
StudentGuanli s=new StudentGuanli();
Scanner input =new Scanner (System.in);
public static void main(String[] args) {
Scanner input =new Scanner (System.in);
Test t=new Test();
while(true){
t.caidan();
int choice;
choice=input.nextInt();
switch (choice) {
case 1:
t.xianshi();
t.fanhui();
break;
case 2:
t.zengjia();
t.fanhui();
break;
case 3:
t.xiugai();
t.fanhui();
t.caidan();
break;
case 4:
t.shanchu();
t.fanhui();
break;
case 5:
t.chazhao();
t.fanhui();
break;
case 6:
t.paixu();
t.fanhui();
break;
case 7:
System.exit(88); //系统直接退出
default:
System.out.println("输出错误!");
break;
}}
}
public void fanhui(){
System.out.println("===========================================");
System.out.println("输入任意数字,返回上一行");
input.next();
}
public void caidan(){
System.out.println("------------------学员管理系统------------------");
System.out.println("\t\t1.查询所有学员");
System.out.println("\t\t2.新增学员信息");
System.out.println("\t\t3.修改学员信息");
System.out.println("\t\t4.删除学员信息");
System.out.println("\t\t5.查询特点学员");
System.out.println("\t\t6.按照成绩排序");
System.out.println("\t\t7.退出");
System.out.println("-----------------------------------------------");
}
public void xianshi(){
List<BaseStudent> gl=s.findAll();
showList(gl);
}
private void showList(List<BaseStudent> gl)
{
System.out.println("================学员信息列表================");
System.out.println("编号\t名字\t性别\t年龄\t班级名称\t学分");
for (BaseStudent baseStudent : gl) {
System.out.println(baseStudent);
}
System.out.println("-----------------------------------------------");
}
public void zengjia(){
System.out.println("请输入学员名字:");
String name1=input.next();
System.out.println("请输入学员性别:(0:男/1:女)");
int i=input.nextInt();
String sex="";
if(i==0){
sex=s.MAN;
}else if(i==1){
sex=s.FEMAN;
}
System.out.println("请输入学员年龄:");
int age=input.nextInt();
System.out.println("请输入学员班级:");
String calssname=input.next();
StudentInfo stu=new StudentInfo(name1,sex,age,calssname);
boolean b=s.addStudent(stu);
if(b){
System.out.println("增加成功");
}else{
System.out.println("添加失败");
}
}
public void xiugai(){
System.out.println("请输入要修改的学生学号");
int i=input.nextInt();
StudentInfo b=(StudentInfo)s.findById(i);
System.out.println("请输入新名字(输入“~”表示不修改)");
String newName=input.next();
if(newName!="~"){
b.setName(newName);
}else{
b.setName(b.getName());
}
System.out.println("请输入新性别(输入“~”表示不修改;0:男/1:女)");
int newi=input.nextInt();
String newsex="";
if(newi==0){
newsex=s.MAN;
}else if(newi==1){
newsex=s.FEMAN;
}
if(newsex!="~"){
b.setSex(newsex);
}else{
b.setSex(b.getSex());
}
System.out.println("请输入新年龄(输入“0”表示不修改");
int newAge=input.nextInt();
if(newAge!=0){
b.setAge(newAge);
}
System.out.println("请输入新班级(输入“~”表示不修改)");
String newbanji=input.next();
if(newbanji!="~"){
b.setBanji(newbanji);
}else{
b.setBanji(b.getBanji());
}
boolean x=s.updatestudent(b);
if(x){
System.out.println("修改成功");
}
else{
System.out.println("修改失败");
}
}
public void shanchu(){
System.out.println("请输入要删除学员id");
int i=input.nextInt();
StudentInfo b=(StudentInfo)s.findById(i);
System.out.println("确定要删除该学员吗?(y/n)");
String x=input.next();
if(x.equals("y")){
boolean a=s.deletestudent(i);
if(a){
System.out.println("删除成功");
}else{
System.out.println("操作失败");
}
}else{
System.out.println("操作失败");
}
}
public void chazhao()
{
System.out.println("请输入要查询的学员名字(支出模糊查询)");
String name=input.next();
List<BaseStudent> gl=s.findAll(name);
showList(gl);
}
public void paixu()
{
List<BaseStudent> stu= s.findAll();
TreeSet<BaseStudent> slist=new TreeSet<BaseStudent>();
slist.addAll(stu);
System.out.println("================学员信息列表================");
System.out.println("编号\t名字\t性别\t年龄\t班级名称\t学分");
for (BaseStudent b : slist) {
System.out.println(b);
}
System.out.println("-----------------------------------------------");
}
}
|
|