码迷,mamicode.com
首页 > 其他好文 > 详细

一个简单的类设计题目

时间:2015-01-05 23:30:23      阅读:357      评论:0      收藏:0      [点我收藏+]

标签:class   简单类设计   

技术分享

代码如下:

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());
	}

}


一个简单的类设计题目

标签:class   简单类设计   

原文地址:http://blog.csdn.net/u014492609/article/details/42434729

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!