昨天复习了一下,今天又尝试做了一次学生管理系统。感觉比上次好了很多。
原先想尝试类似c++的system(“cls”)清屏,结果遇到了问题,明天继续
package 学生成绩管理系统;
import java.util.*;
@SuppressWarnings("unused")
public class Student {
private String StudentNumber;
private String name;
private int age;
private boolean sex;
private double score;
Scanner in=new Scanner(System.in);
public Student() {
StudentNumber="00000000";
name="***";
age=0;
sex=false;
score=0;
}
public String GetStudentNumber() {
return StudentNumber;
}
public String GetName() {
return name;
}
public int GetAge() {
return age;
}
public boolean GetSex() {
return sex;
}
public double GetScore() {
return score;
}
public void SetStudentNumber() {
StudentNumber=in.next();
}
public void SetName() {
name=in.next();
}
public void SetAge() {
age=in.nextInt();
}
public void SetSex() {
String temp;
System.out.print("please input sex male or female:");
temp=in.next();
if(temp=="male")
sex=false;
else if(temp=="female")
sex=true;
//else {
//System.out.println("input error i wanna goto but not have,please exit");
//}
}
public void SetScore() {
score=in.nextDouble();
}
}
package 学生成绩管理系统;
import java.util.*;
@SuppressWarnings({ "unchecked", "rawtypes" })
public class StudentManager {
int n=5;
Student []A=new Student[n];
Scanner in=new Scanner(System.in);
void show() {
System.out.println("****************************************************************");
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("****************************************************************");
}
void SelsctStudent() {
int i;
String num;
System.out.print("plaese input StudentNumber:");
num=in.next();
for(i=0;i<n;i++)
if(A[i].GetStudentNumber()==num)
{
System.out.print(" id:");
System.out.print(A[i].GetStudentNumber());
System.out.print(" name:");
System.out.print(A[i].GetName());
System.out.print(" age:");
System.out.print(A[i].GetAge());
System.out.print(" sex(false==male,true==famale):");
System.out.print(A[i].GetSex());
System.out.print(" score:");
System.out.print(A[i].GetScore());
break;
}
}
void UpdateStudent() {
int i;
Student B;
B=Set();
for(i=0;i<n;i++)
if(B.GetStudentNumber()==A[i].GetStudentNumber())
break;
List<Student> list=new ArrayList(Arrays.asList(A));
list.set(i, B);
Student[] ne=new Student[list.size()];
list.toArray(ne);
A=ne;
}
void DeleteStudent() {
int i;
String num;
System.out.print("plaese input StudentNumber:");
num=in.next();
for(i=0;i<n;i++)
if(A[i].GetStudentNumber()==num)
break;
List<Student> list=new ArrayList(Arrays.asList(A));
list.remove(i);
Student[] ne=new Student[list.size()];
list.toArray(ne);
A=ne;
n--;
}
void AddStudent(){
Student B;
List<Student> list=new ArrayList(Arrays.asList(A));
B=Set();
for(int i=0;i<n;i++)
if(B.GetStudentNumber()==A[i].GetStudentNumber())
{
System.out.print("重复,请重新输入");
B=Set();
break;
}
list.add(B);
Student[] ne=new Student[list.size()];
list.toArray(ne);
A=ne;
n++;
}
void ShowStudent() {
for(Student element:A)
System.out.println(element);
}
void SetStudent() {
for(int i=0;i<n;i++)
A[i]=Set();
}
Student Set() {
Student temp = new Student();
System.out.println("please enter in turn");
System.out.println("StudentNumber Name Age Sex Score");
temp.SetStudentNumber();
temp.SetName();
temp.SetAge();
temp.SetSex();
temp.SetScore();
return temp;
}
}
package 学生成绩管理系统;
/*import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;*/
import java.util.*;
public class zhu {
public static void main(String[] args) {
StudentManager A = new StudentManager();
int choice;
@SuppressWarnings("resource")
Scanner in=new Scanner(System.in);
A.SetStudent();
//clear();
while(true)
{
A.show();
choice=in.nextInt();
if(choice==1)
{
A.ShowStudent();
}
else if(choice==2)
{
A.AddStudent();
}
else if(choice==3)
{
A.DeleteStudent();
}
else if(choice==4)
{
A.UpdateStudent();
}
else if(choice==5)
{
A.SelsctStudent();
}
else
{
char cho=0;
System.out.print("exit? Y/N");
choice=in.nextInt();
if(cho=='Y')
break;
}
}
}
}