java练习---计算平均分和总成绩

import java.util.Scanner;

public class ScoreCalc {
	int Java;
	int C;
	int DB;

	public int calca() {
		int sum = Java + C + DB;
		return sum;
	}

	public void showa() {
		System.out.println("总成绩是:" + calca());
	}

	public double calcAvg() {
		double avg = (Java + C + DB) / 3.0;
		return avg;
	}

	public void showAvg() {
		System.out.println("平均成绩是:" + calcAvg());
	}

	public static void main(String[] args) {
		ScoreCalc s = new ScoreCalc();
		Scanner input = new Scanner(System.in);
		System.out.println("请输入Java成绩:");
		s.Java = input.nextInt();
		System.out.println("请输入C#成绩:");
		s.C = input.nextInt();
		System.out.println("请输入DB成绩:");
		s.DB = input.nextInt();
		s.showa();
		s.showAvg();
	}
}

你可能感兴趣的:(Java练习)