package com.itcast.classes;
import java.util.Scanner;
public class StudentScoreManager {
/**
* @param args
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("**********欢迎进入学生成绩管理系统**********");
System.out.println("*****************************************");
System.out.println("请输入学生人数:");
int index = input.nextInt();
Student[] stu = new Student[index];
int scoreChinese = 0;
int scoreMath = 0;
int scoreEnglish = 0;
int scores = 0;
for (int i = 0; i < index; i++) {
// 输入第i个学生的语文成绩
int inC = 0;
Student st = new Student();
do {
System.out.println("请输入第" + (i + 1) + "个学生的语文成绩");
inC = input.nextInt();
if (inC >= 0 & inC <= 150) {
st.setChineseScore(inC);
stu[i] = st;
} else {
System.out.println("您输入的成绩不合法!以下请按要求输入。。。");
}
} while(inC < 0 || inC > 150);
// 输入第i个学生的数学成绩
int inM = 0;
do {
System.out.println("请输入第" + (i + 1) + "个学生的数学成绩");
inM = input.nextInt();
if (inM >= 0 & inM <= 150) {
st.setMathScore(inM);
stu[i] = st;
} else {
System.out.println("您输入的成绩不合法!以下请按要求输入。。。");
}
} while(inM < 0 || inM > 150);
//输入第i个学生的英语成绩
int inE = 0;
do {
System.out.println("请输入第" + (i + 1) + "个学生的英语成绩");
inE = input.nextInt();
if (inE >= 0 & inE <= 150) {
st.setEnglishScore(inE);
stu[i] = st;
} else {
System.out.println("您输入的成绩不合法!请按要求输入。。。");
}
} while(inE < 0 || inE > 150);
System.out.println();
}
// 打印出学生的成绩
for (int j = 0; j < index; j++) {
System.out.println("第" + (j + 1) + "个学生的语文成绩为:"
+ stu[j].getChineseScore());
System.out.println("第" + (j + 1) + "个学生的数学成绩为:"
+ stu[j].getMathScore());
System.out.println("第" + (j + 1) + "个学生的英语成绩为:"
+ stu[j].getEnglishScore());
scores = stu[j].getChineseScore() + stu[j].getMathScore()
+ stu[j].getEnglishScore();
System.out.println("第" + (j + 1) + "个学生的总成绩为:" + scores);
System.out.println("第" + (j + 1) + "个学生的平均成绩为:" + (scores / 3));
System.out.println("******************");
// new Student().dispaly(stu[j]);
}
System.out.println("是否更改学生成绩:1、是 、\t 2、否");
int is = input.nextInt();
if (is == 1) {
// 更改学生成绩信息
System.out.println("<-----更改第几个学生的成绩----->");
int i = input.nextInt();
if (i <= index & i > 0) {
System.out.println("<-----更改第" + i + "个学生的成绩----->");
System.out.println("***1、语文成绩***" + "\t***2、数学成绩***"
+ "\t***3、英语成绩***" + "\t***4、退出***");
int key = input.nextInt();
Student s = new Student();
switch (key) {
// 更改学生语文成绩
case 1:
System.out.println("请输入语文成绩:");
int score1 = input.nextInt();
if (score1 >= 0 & score1 <= 150) {
stu[i - 1].setChineseScore(score1);
s.dispaly(stu[i - 1]);
} else {
System.out.println("您输入的成绩不合法! 请重新运行程序。。。");
break;
}
break;
// 更改学生数学成绩
case 2:
System.out.println("请输入数学成绩:");
int score2 = input.nextInt();
if (score2 >= 0 & score2 <= 150) {
stu[i - 1].setMathScore(score2);
s.dispaly(stu[i - 1]);
} else {
System.out.println("您输入的成绩不合法! 请重新运行程序。。。");
break;
}
break;
// 更改学生外语成绩
case 3:
System.out.println("请输入英语成绩:");
int score3 = input.nextInt();
if (score3 >= 0 & score3 <= 150) {
stu[i - 1].setEnglishScore(score3);
s.dispaly(stu[i - 1]);
} else {
System.out.println("您输入的成绩不合法! 请重新运行程序。。。");
break;
}
break;
case 4:
System.out.println("系统退出,谢谢使用。。。");
System.out.println("本系统由小王版权所有!");
break;
default:
System.out.println("您输入的不再更改范围内!");
break;
}
} else {
System.out.println("对不起!您输入的有误!请重新运行程序。。。");
}
} else {
System.out.println("系统退出,谢谢使用。。。");
System.out.println("本系统由小王版权所有!");
System.exit(0);
}
}
}
// 建立学生类
class Student {
private int chineseScore;
private int mathScore;
private int englishScore;
public int getChineseScore() {
return chineseScore;
}
public void setChineseScore(int chineseScore) {
this.chineseScore = chineseScore;
}
public int getMathScore() {
return mathScore;
}
public void setMathScore(int mathScore) {
this.mathScore = mathScore;
}
public int getEnglishScore() {
return englishScore;
}
public void setEnglishScore(int englishScore) {
this.englishScore = englishScore;
}
public static void dispaly(Student s) {
System.out.println("更改后的语文成绩为:" + s.getChineseScore());
System.out.println("更改后的数学成绩为:" + s.getMathScore());
System.out.println("更改后的英语成绩为:" + s.getEnglishScore());
}
}