java设计一个类ScoreCacl,类下有属性java,DB2,jsp,定义求三门课程成绩的和及平均值方法,建立测试类。
时间: 2024-04-29 16:25:42 浏览: 75
编写程序计算三门课的平均成绩,要求应用程序分别用Java不同的循环语句实现。
3星 · 编辑精心推荐
以下是ScoreCacl类和测试类的代码:
```java
public class ScoreCalc {
private double java;
private double DB2;
private double jsp;
public ScoreCalc(double java, double DB2, double jsp) {
this.java = java;
this.DB2 = DB2;
this.jsp = jsp;
}
public double getTotalScore() {
return java + DB2 + jsp;
}
public double getAverageScore() {
return getTotalScore() / 3;
}
}
```
```java
public class ScoreCalcTest {
public static void main(String[] args) {
ScoreCalc scoreCalc = new ScoreCalc(80, 85, 90);
System.out.println("Total Score: " + scoreCalc.getTotalScore());
System.out.println("Average Score: " + scoreCalc.getAverageScore());
}
}
```
测试结果为:
```
Total Score: 255.0
Average Score: 85.0
```
阅读全文