?? studentsystem.java
字號:
int m = 0;
for (int i =0;i<count;i++)
{
if(sno.equals(all_students[i].sno))
{
m = i;
break;
}
}
for(int j=m;j<count-1;j++)
{
all_students[j] = all_students[j+1];
}
count--;
}
void printAllStudents() //打印所有的學生信息
{
System.out.println("——————————");
System.out.println("學號 姓名 性別 成績");
for(int i=0;i<count;i++)
{
System.out.println(all_students[i].sno+" "+all_students[i].sname+" "+all_students[i].sex+" "+all_students[i].score);
}
System.out.println("——————————");
if(count == 0)
{
System.out.println();
System.out.println("***沒有學生信息!***");
System.out.println();
}
else
{
System.out.println("——總計:"+StudentArrangement.count+" 條學生信息!");
System.out.println();
}
}
void show1()
{
System.out.println("*************************************");
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.排列學生信息! ***");
System.out.println("*** 6.打印學生信息! ***");
System.out.println("*** 7.全部刪除學生信息! ***");
System.out.println("*** 8.作者信息! ***");
System.out.println("*** 0.退出判斷! ***");
System.out.println("*************************************");
System.out.println("*************************************");
System.out.println("請選擇判斷: (0……8)");
}
void show2()
{
System.out.println("************************");
System.out.println("*** 1.按學號查詢: ***");
System.out.println("*** 2.按姓名查詢: ***");
System.out.println("*** 3.按成績查詢: ***");
System.out.println("*** 0.退出查詢操作!***");
System.out.println("************************");
System.out.println("請選擇查詢方式: (0……3)");
}
void show3()
{
System.out.println("************************");
System.out.println("*** 1.按學號排序: ***");
System.out.println("*** 2.按成績排序: ***");
System.out.println("*** 0.退出排序操作!***");
System.out.println("************************");
System.out.println("請選擇排序方式: (0……2)");
}
}
public class StudentSystem
{
public static void main(String args[])
{
Student[] new_student= new Student[50];
new_student[0]=new Student("200901","張三","F","60");
new_student[1]=new Student("200904","李四","M","83");
new_student[2]=new Student("200902","王五","F","70");
new_student[3]=new Student("200909","張三","M","97");
new_student[4]=new Student("200906","小明","M","70");
new_student[5]=new Student("200908","王康","M","65");
new_student[6]=new Student("200910","劉剛","M","50");
new_student[7]=new Student("200905","張梅","F","100");
new_student[8]=new Student("200907","郭華","M","76");
new_student[9]=new Student("200903","趙六","M","83");
StudentArrangement m = new StudentArrangement();
m.all_students = new_student;
StudentArrangement.count = 10;
m.show1();
Scanner sc1 = new Scanner(System.in);
int temp1 = sc1.nextInt();
while (temp1 != 0)
{
switch(temp1)
{
case 1 : // 添加學生信息
System.out.println("***添加學生信息:***");
System.out.println("——請輸入學號:(六位數字并且前四位為2009)");
String args1 = sc1.next();
//判斷輸入的學號是否有誤(合法、唯一),有誤請重新輸入
while(m.addStudentJudgeSno(args1) == 0 || m.addStudentJudgeSnoUnique(args1) == 0)
{
System.out.println("您輸入的學號不對,請重新輸入:");
args1 = sc1.next();
if(m.addStudentJudgeSno(args1) == 1 && m.addStudentJudgeSnoUnique(args1) == 1)
{
break;
}
}
System.out.println("——請輸入姓名:");
String args2 = sc1.next();
System.out.println("——請輸入性別:(F/M)");
String args3 = sc1.next();
//判斷輸入的性別是否合法,不合法請重新輸入
while(m.addStudentJudgeSex(args3) != 1)
{
System.out.println("您輸入的性別不合法,請重新輸入:");
args3 = sc1.next();
if(m.addStudentJudgeSex(args3) == 1)
{
break;
}
}
System.out.println("——請輸入成績:(10……100)");
String args4 = sc1.next();
//判斷輸入的成績是否合法,不合法請重新輸入
while(m.addStudentJudgeScore(args4) != 1)
{
System.out.println("您輸入的成績不合法,請重新輸入:");
args4 = sc1.next();
if(m.addStudentJudgeScore(args4) == 1)
{
break;
}
}
Student t = new Student(args1,args2,args3,args4);
m.addStudent(t);
System.out.println("——添加成功!");
System.out.println();
break;
case 2 : // 查詢學生信息(按不同方式查詢)
m.show2();
Scanner sc2 = new Scanner(System.in);
int temp2 = sc2.nextInt();
while (temp2 != 0)
{
switch(temp2)
{
case 1 :
System.out.println("——請輸入學號:");
String args5 = sc2.next();
m.searchStudentSno(args5);
System.out.println();
break;
case 2 :
System.out.println("——請輸入姓名:");
String args6 = sc2.next();
m.searchStudentSname(args6);
System.out.println();
break;
case 3 :
System.out.println("——請輸入成績:");
String args7 = sc2.next();
m.searchStudentScore(args7);
System.out.println();
break;
}
m.show2();
temp2 = sc2.nextInt();
}
break;
case 3 : // 修改學生信息
System.out.println("——請輸入要修改的學生學號:");
String args8 = sc1.next();
m.searchStudentSno(args8);
if(m.number == 0)
{
System.out.println("請選擇其他操作:");
break;
}
System.out.println("修改該學生的成績為:");
String args9 = sc1.next();
//判斷輸入的成績是否合法,不合法請重新輸入
while(m.addStudentJudgeScore(args9) != 1)
{
System.out.println("您輸入的成績不合法,請重新輸入:");
args9 = sc1.next();
if(m.addStudentJudgeScore(args9) == 1)
{
break;
}
}
m.modifyStudentSno(args8,args9);
System.out.println("——修改成功");
System.out.println();
break;
case 4 : // 刪除學生信息
System.out.println("請輸入要刪除的學生學號:");
String args10 = sc1.next();
m.searchStudentSno(args10);
if(m.number == 0)
{
System.out.println("請選擇其他操作:");
break;
}
System.out.println("確定要刪除學號為: "+args10+" 的學生信息嗎?");
System.out.println("***是,請按1***"+" "+"***退出刪除操作,請按0***");
Scanner sc3 = new Scanner(System.in);
int temp3 = sc3.nextInt();
while (temp3 != 0)
{
switch(temp3)
{
case 1 :
m.deleteStudent(args10);
System.out.println();
System.out.println("——刪除成功!");
System.out.println();
System.out.println("——請按0退出刪除操作");
break;
}
temp3 = sc3.nextInt();
}
break;
case 5 : // 排列學生信息
m.show3();
Scanner sc4 = new Scanner(System.in);
int temp4 = sc4.nextInt();
while (temp4 != 0)
{
switch(temp4)
{
case 1 :
m.arrangeALLStudentSno();
System.out.println("排列后所有的學生信息如下:");
m.printAllStudents();
break;
case 2 :
m.arrangeALLStudentScore();
System.out.println("排列后所有的學生信息如下:");
m.printAllStudents();
break;
}
m.show3();
temp4 = sc4.nextInt();
}
break;
case 6 : // 打印全部學生信息
System.out.println("所有的學生信息打印如下:");
m.printAllStudents();
break;
case 7 : // 刪除全部學生信息
System.out.println("確定要刪除所有的學生信息嗎?");
System.out.println("***是,請按1***"+" "+"***退出刪除操作,請按0***");
Scanner sc5 = new Scanner(System.in);
int temp5 = sc5.nextInt();
while (temp5 != 0)
{
switch(temp5)
{
case 1 :
StudentArrangement.count = 0;
System.out.println();
System.out.println("——全部學生信息已刪除!");
System.out.println();
System.out.println("——請按0退出刪除操作");
}
temp5 = sc5.nextInt();
}
break;
case 8 : // 打印作者信息
System.out.println("Version: "+"1.0"+" "+"Copyright: "+"劉少波");
break;
}
m.show1();
temp1 = sc1.nextInt();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -