12章上机练习1

时间:2023-02-13 09:05:11
从键盘上输入3门课的分数,计算3门课的平均分和总成绩,编写成绩计算类实现功能
 
public class C {int java;// java成绩int c;// c#成绩int db;// DB成绩// 计算总成绩public int calczongScore() {int total = java+ c + db;return total;}// 显示总成绩public void showTotalScore() {System.out.println("总成绩是:" + calcTotalScore());}// 计算总成绩public double calcAvg() {double avg = (java+ c + db) / 3.0;return avg;} // 显示平均成绩public void showAvg() {System.out.println("平均成绩是:" + calcAvg());}}

import java.util.Scanner;

public class D {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
C j = new C();
Scanner input = new Scanner(System.in);
System.out.println("请输入java成绩:");
j.java = input.nextInt();
System.out.println("请输入c成绩:");
j.c = input.nextInt();
System.out.println("请输入db成绩:");
j.db = input.nextInt();
j.showTotalScore();
j.showAvg();

}

}