/*定义并测试一个Student类
*包括属性,学号,姓名,以及三门成绩,数学,英语,计算机
*算总分,平均分,最高分,最低分
*/public class Student
{
private String no;
private String name;
private int math = 0;
private int eng = 0;
private int comp = 0;
//构造函数
Student(String no, String name)
{
this.no = no;
this.name = name;
}
Student(String no, String name, int math, int eng, int comp)
{
this(no, name);
this.math = math;
this.eng = eng;
this.comp = comp;
}
//取值
public String getNo()
{
return no;
}
public String getName()
{
return name;
}
public int getMath()
{
return math;
}
public int getEng()
{
return eng;
}
public int getComp()
{
return comp;
}
//附值
public void setName(String name)
{
this.name = name;
}
public void setMath(int math)
{
this.math = math;
}
public void setEng(int eng)
{
this.eng = eng;
}
public void setComp(int comp)
{
this.comp = comp;
}
//算总分
public int sum()
{
return(math + eng + comp);
}
//平均分
public int arg()
{
return(sum() /3);
}
//最高分
public int max()
{
int tmp = Math.max(math, eng);
if(tmp < comp)
{
tmp = comp;
}
return tmp;
}
//最低分
public int min()
{
int tmp = Math.min(math, eng);
if(tmp > comp)
{
tmp = comp;
}
return tmp;
}
public static void main(String argv[])
{
Student s = new Student("9772039", "Mechile");
s.setMath(90);
s.setEng(82);
s.setComp(89);
System.out.println("Student "+ s.getName() +" sum:" + s.sum());
System.out.println("Student "+ s.getName() +" arg:" + s.arg());
System.out.println("Student "+ s.getName() +" max:" + s.max());
System.out.println("Student "+ s.getName() +" min:" + s.min());
}
}
*包括属性,学号,姓名,以及三门成绩,数学,英语,计算机
*算总分,平均分,最高分,最低分
*/public class Student
{
private String no;
private String name;
private int math = 0;
private int eng = 0;
private int comp = 0;
//构造函数
Student(String no, String name)
{
this.no = no;
this.name = name;
}
Student(String no, String name, int math, int eng, int comp)
{
this(no, name);
this.math = math;
this.eng = eng;
this.comp = comp;
}
//取值
public String getNo()
{
return no;
}
public String getName()
{
return name;
}
public int getMath()
{
return math;
}
public int getEng()
{
return eng;
}
public int getComp()
{
return comp;
}
//附值
public void setName(String name)
{
this.name = name;
}
public void setMath(int math)
{
this.math = math;
}
public void setEng(int eng)
{
this.eng = eng;
}
public void setComp(int comp)
{
this.comp = comp;
}
//算总分
public int sum()
{
return(math + eng + comp);
}
//平均分
public int arg()
{
return(sum() /3);
}
//最高分
public int max()
{
int tmp = Math.max(math, eng);
if(tmp < comp)
{
tmp = comp;
}
return tmp;
}
//最低分
public int min()
{
int tmp = Math.min(math, eng);
if(tmp > comp)
{
tmp = comp;
}
return tmp;
}
public static void main(String argv[])
{
Student s = new Student("9772039", "Mechile");
s.setMath(90);
s.setEng(82);
s.setComp(89);
System.out.println("Student "+ s.getName() +" sum:" + s.sum());
System.out.println("Student "+ s.getName() +" arg:" + s.arg());
System.out.println("Student "+ s.getName() +" max:" + s.max());
System.out.println("Student "+ s.getName() +" min:" + s.min());
}
}
解决方案 »
- 喜欢juv_rmtp_client.jar的高手们,来帮下忙哦!
- 简单小问题 && || 区别
- 我的输入这块 什么问题呀?请赐教!
- 用java如何打开
- URL中的%...怎么转换成中文...
- 提问给分
- 如何锁定源代码,一次只能有一个线程使用?
- 我是刚学JBUILDER7 的(不到一个星期),问:每次,增加增件时,根本没法调整大小?即使调整也是那个(NORTH,WEST,TOP.....)类型的。难道
- 请问各位ActionListener接口中的actionPerformed方法到底是什么意思,是不是类似bcb中的onclick事件?
- 紧急求助,如何关闭applet里面的frame?
- 访问Access数据库报错,请帮忙看看
- 请问国内人气比较旺的软件工程论坛有哪些 ?
Student Mechile arg:87
Student Mechile max:90
Student Mechile min:82Process completed.
刚现写的,希望你不是用来交作业。