JAVA简单加急:从键盘接收三门课分数,计算三门课的平均分和总成绩,编写成绩计算类实现功能
答案:1 悬赏:20 手机版
解决时间 2021-03-23 05:33
- 提问者网友:饥饿走向夜
- 2021-03-22 23:05
JAVA简单加急:从键盘接收三门课分数,计算三门课的平均分和总成绩,编写成绩计算类实现功能
最佳答案
- 五星知识达人网友:拾荒鲤
- 2021-03-23 00:26
import java.util.Scanner;
public class ScoreCale {
public static void main(String[] args) {
ScoreCale sc = new ScoreCale();
System.out.println("总成绩是:" + sc.getTotalScores());
System.out.println("平均成绩是:" + sc.getAvgScores());
}
private double javaScore;
private double csharpeScore;
private double dbScore;
public ScoreCale() {
input();
}
public void input() {
Scanner s = new Scanner(System.in);
System.out.print("请输入Java的分数:");
javaScore = s.nextDouble();
System.out.print("请输入C#的分数:");
csharpeScore = s.nextDouble();
System.out.print("请输入db的分数:");
dbScore = s.nextDouble();
}
public double getTotalScores() {
return javaScore + csharpeScore + dbScore;
}
public double getAvgScores() {
return (javaScore + csharpeScore + dbScore) / 3;
}
}
//你就自己再建一个测试类,把main方法拷贝过去就可以了追问main的方法?就是这代码不是太完整是么追答对,你就new一个类,类名随你,之后把
public static void main(String[] args) {
ScoreCale sc = new ScoreCale();
System.out.println("总成绩是:" + sc.getTotalScores());
System.out.println("平均成绩是:" + sc.getAvgScores());
}
这段话拷过去即可追问NEW一个类是什么意思
public class ScoreCale {
public static void main(String[] args) {
ScoreCale sc = new ScoreCale();
System.out.println("总成绩是:" + sc.getTotalScores());
System.out.println("平均成绩是:" + sc.getAvgScores());
}
private double javaScore;
private double csharpeScore;
private double dbScore;
public ScoreCale() {
input();
}
public void input() {
Scanner s = new Scanner(System.in);
System.out.print("请输入Java的分数:");
javaScore = s.nextDouble();
System.out.print("请输入C#的分数:");
csharpeScore = s.nextDouble();
System.out.print("请输入db的分数:");
dbScore = s.nextDouble();
}
public double getTotalScores() {
return javaScore + csharpeScore + dbScore;
}
public double getAvgScores() {
return (javaScore + csharpeScore + dbScore) / 3;
}
}
//你就自己再建一个测试类,把main方法拷贝过去就可以了追问main的方法?就是这代码不是太完整是么追答对,你就new一个类,类名随你,之后把
public static void main(String[] args) {
ScoreCale sc = new ScoreCale();
System.out.println("总成绩是:" + sc.getTotalScores());
System.out.println("平均成绩是:" + sc.getAvgScores());
}
这段话拷过去即可追问NEW一个类是什么意思
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯