首页 > 代码库 > 一个简单的类设计题目

一个简单的类设计题目

技术分享

代码如下:

class Student{
private String name;
private int age;
private float english;
private float math;
private float computer;
public Student(){};
public Student(String name,int age,float english,float math,float computer){
	this.setName(name);
	this.setAge(age);
	this.setEnglish(english);
	this.setMath(math);
	this.setComputer(computer);
}
public float sum(){
	return math+computer+english;
}
public float max(){
	float max=math>computer?math:computer;
	max=max>english?max:english;
	return max;
}
public float ave(){
	return math+computer+english/3;
}
public String getName() {
	return name;
}
public void setName(String name) {
	this.name = name;
}
public int getAge() {
	return age;
}
public void setAge(int age) {
	this.age = age;
}

public float getEnglish() {
	return english;
}
public void setEnglish(float english) {
	this.english = english;
}
public float getMath() {
	return math;
}
public void setMath(float math) {
	this.math = math;
}
public float getComputer() {
	return computer;
}
public void setComputer(float computer) {
	this.computer = computer;
}
}
public class StudentDemo1 {

	public static void main(String[] args) {
		Student S=new Student("奥巴马",56,35,88,19);
		System.out.println(S.getName());
		System.out.println(S.getAge());
		System.out.println(S.getComputer());
		System.out.println(S.getEnglish());
		System.out.println(S.getMath());
		System.out.println(S.sum());
		System.out.println(S.ave());
		System.out.println(S.max());
	}

}


一个简单的类设计题目