JAVA_面向对象_练习_封装_02_EncapsulationDaemon02.java

/**
 * 封装一个学生类,有姓名,有年龄,有性别,有英语成绩,数学成绩,
 * 语文成绩,封装方法,求总分,平均分,以及打印学生的信息。
 */
public class EncapsulationDaemon02{
	public static void main(String[] args){
		Mate m1 = new Mate("Han Meimei",88,"girl",50,50,52);
		m1.total();
		m1.average();
		m1.info();
	}
}
class Mate{
	private String name;
	private int age;
	private String sex;
	private int scoreEnglish;
	private int scoreMath;
	private int scoreChinese;
	
	public Mate(String name,int age,String sex,int scoreEnglish,int scoreMath,int scoreChinese){
		this.name = name;
		this.age = age;
		this.sex = sex;
		this.scoreEnglish = scoreEnglish;
		this.scoreMath = scoreMath;
		this.scoreChinese = scoreChinese;
		System.out.println(name+age+sex+scoreEnglish+scoreMath+scoreChinese);
	}
	
	public void total(){
		int total = scoreEnglish + scoreMath + scoreChinese;
		System.out.println(total);
	}
	public void average(){
		int total = scoreEnglish + scoreMath + scoreChinese;
		float average = (float)total/3;
		System.out.println(average);
	}
	public void info(){
		System.out.println(name+age+sex);
	}
}

你可能感兴趣的:(JAVA_面向对象_练习_封装_02_EncapsulationDaemon02.java)