java老师让周日交学生成绩档案管理系统~~
- 提问者网友:你挡着我发光了
- 2021-04-15 16:31
- 五星知识达人网友:猎心人
- 2021-04-15 17:59
import java.io.*;
import java.util.Scanner;
//学生类
class Student{
public static int count=0;
private String id;
private String name;
private int age;
private int score1;
private int score2;
public Student(String id,String name,String age,String score1,String score2){
this.id=id;
this.name=name;
this.age=Integer.parseInt(age);
this.score1=Integer.parseInt(score1);
this.score2=Integer.parseInt(score2);
}
public Student(String id,String name,int age,int score1,int score2){
this.id=id;
this.name=name;
this.age=age;
this.score1=score1;
this.score2=score2;
}
public String GetId(){
return id;
}
public String GetName(){
return name;
}
public int GetAge(){
return age;
}
public int GetScore1(){
return score1;
}
public int GetScore2(){
return score2;
}
public void Display(){
System.out.println(id+"\t"+name+"\t"+age+"\t"+score1+"\t"+score2);
}
public Student(){
}
}
//学生成绩管理系统
public class StudentInfo{
public static final int MAX=100;
public static Student[] stu=new Student[MAX];
public static void Output()throws IOException{
PrintWriter br=new PrintWriter(new BufferedWriter(new FileWriter("student.in")));
br.println("id\tname\tage\tscore1\tscore2");
for(int i=0;i<Student.count;i++){
br.println(stu[i].GetId()+"\t"+stu[i].GetName()+"\t"+stu[i].GetAge()+"\t"+stu[i].GetScore1()+"\t"+stu[i].GetScore2());
}
br.close();
}
public static void Input(){
//BufferedReader br=new BufferedReader(new FileReader("student.out"));
try{
Scanner sc=new Scanner(new FileReader("student.in"));
String str;
for(int i=0;i<5;i++){
str=sc.next();
}
String[] str1=new String[5];
for(int j=0;j<MAX;j++){
for(int i=0;i<5;i++){
str1[i]=sc.next();
}
stu[j]=new Student(str1[0],str1[1],str1[2],str1[3],str1[4]);
Student.count++;
}
}
catch(Exception e){
System.out.println("The end!");
}
}
public static void InitSystem()throws IOException{
System.out.println("Welcom to the StudentInfo System!");
System.out.println("[0].Exit the System.");
System.out.println("[1].Input the students' information.");
System.out.println("[2].Add a student's information.");
System.out.println("[3].Delete a student's information.");
System.out.println("[4].Display all information.");
String str;
System.out.print("Input your choice:");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
str=br.readLine();
int i=Integer.parseInt(str);
switch(i){
case 1:
InputStuInfo();
InitSystem();
break;
case 2:
AddStuInfo();
InitSystem();
break;
case 3:
DelStuInfo();
InitSystem();
break;
case 4:
Display();
InitSystem();
break;
case 0:
System.exit(1);
break;
default:
InitSystem();
break;
}
}
public static void InputStuInfo() throws IOException{
String[] str=new String[5];
String str1;
for(int i=0;Student.count!=0;i++){
Student.count--;
}
System.out.println("id\tname\tage\tscore1\tscore2");
//Student[] stu=new Student[6];
outer:
for(int j=0;j<MAX;j++){
Scanner sc=new Scanner(System.in);
for(int i=0;i<5;i++){
str[i]=sc.next();
if(str[i].equals("end"))
break outer;
}
stu[j]=new Student(str[0],str[1],str[2],str[3],str[4]);
Student.count++;
}
Output();
}
public static void AddStuInfo()throws IOException{
String[] str=new String[5];
String str1;
Scanner sc=new Scanner(System.in);
System.out.println("id\tname\tage\tscore1\tscore2");
for(int i=0;i<5;i++)
str[i]=sc.next();
if(Student.count==MAX){
System.out.println("Can't add Student,The system is full");
}
else{
stu[Student.count]=new Student(str[0],str[1],str[2],str[3],str[4]);
Student.count++;
}
Output();
}
public static void DelStuInfo()throws IOException{
System.out.print("Please input the id of the student you want to delete:");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str=br.readLine();
int i;
i=Search(str);
if(i==-1)
System.out.println("Can't find the student"+str);
else{
System.out.println("You delete the student:"+stu[i].GetName());
for(int temp=i;temp<Student.count-1;temp++)
stu[temp]=new Student(stu[temp+1].GetId(),stu[temp+1].GetName(),stu[temp+1].GetAge(),stu[temp+1].GetScore1(),stu[temp+1].GetScore2());
Student.count--;
Output();
}
}
public static void Display(){
System.out.println("id\tname\tage\tscore1\tscore2");
for(int i=0;i<Student.count;i++){
stu[i].Display();
}
}
public static int Search(String str){
int i;
for(i=0;i<MAX;i++){
if(str.equals(stu[i].GetId()))
break;
}
if(i==MAX)
return -1;
else
return i;
}
public static void main(String[] args)throws IOException{
Input();
InitSystem();
}
}
- 1楼网友:空山清雨
- 2021-04-15 20:52
你不晓得学生成绩档案管理系统需要说明需求???
就是需要 学生个人信息(比如:年龄,姓名....),科目信息(比如:语文,数学...),班级信息,年纪信息
- 2楼网友:老鼠爱大米
- 2021-04-15 19:38