JAVA写个计算三个学生TOM,MARRY,JOHN的英语数学各科总成绩和平均成绩
时间: 2024-05-24 10:12:46 浏览: 6
public class Student {
private String name;
private int mathScore;
private int englishScore;
public Student(String name, int mathScore, int englishScore) {
this.name = name;
this.mathScore = mathScore;
this.englishScore = englishScore;
}
public String getName() {
return name;
}
public int getMathScore() {
return mathScore;
}
public int getEnglishScore() {
return englishScore;
}
public int getTotalScore() {
return mathScore + englishScore;
}
public double getAverageScore() {
return getTotalScore() / 2.0;
}
}
public class Main {
public static void main(String[] args) {
Student tom = new Student("Tom", 80, 85);
Student marry = new Student("Marry", 90, 95);
Student john = new Student("John", 75, 80);
int totalMathScore = tom.getMathScore() + marry.getMathScore() + john.getMathScore();
int totalEnglishScore = tom.getEnglishScore() + marry.getEnglishScore() + john.getEnglishScore();
int totalScore = totalMathScore + totalEnglishScore;
double averageScore = totalScore / 6.0;
System.out.println("Total Math Score: " + totalMathScore);
System.out.println("Total English Score: " + totalEnglishScore);
System.out.println("Total Score: " + totalScore);
System.out.println("Average Score: " + averageScore);
}
}
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)