定义学生类student,包含学生的学号,姓名,年龄和三门课程的成级,并计算每个学生的平均成绩和最高分,
展开全部
这是学生类:
public class Student {
private int xuehao;
private String xingming;
private String xingbie;
private int shuxue;
private int yuwen;
private int yingyu;
public int getShuxue() {
return shuxue;
}
public void setShuxue(int shuxue) {
this.shuxue = shuxue;
}
public String getXingbie() {
return xingbie;
}
public void setXingbie(String xingbie) {
this.xingbie = xingbie;
}
public String getXingming() {
return xingming;
}
public void setXingming(String xingming) {
this.xingming = xingming;
}
public int getXuehao() {
return xuehao;
}
public void setXuehao(int xuehao) {
this.xuehao = xuehao;
}
public int getYingyu() {
return yingyu;
}
public void setYingyu(int yingyu) {
this.yingyu = yingyu;
}
public int getYuwen() {
return yuwen;
}
public void setYuwen(int yuwen) {
this.yuwen = yuwen;
}
public int average(int x,int y,int z){
return (x+y+z)/3;
}
}
这是测试类:
public class TestStudent{
public static void main(String args[]) {
Student st1=new Student();
st1.setShuxue(75);
st1.setYingyu(80);
st1.setYuwen(85);
System.out.println("第一个学生的平均成绩为:"+st1.average(st1.getShuxue(),st1.getYingyu(),st1.getYuwen()));
Student st2=new Student();
Student st3=new Student();
Student st4=new Student();
Student st5=new Student();
}
}
public class Student {
private int xuehao;
private String xingming;
private String xingbie;
private int shuxue;
private int yuwen;
private int yingyu;
public int getShuxue() {
return shuxue;
}
public void setShuxue(int shuxue) {
this.shuxue = shuxue;
}
public String getXingbie() {
return xingbie;
}
public void setXingbie(String xingbie) {
this.xingbie = xingbie;
}
public String getXingming() {
return xingming;
}
public void setXingming(String xingming) {
this.xingming = xingming;
}
public int getXuehao() {
return xuehao;
}
public void setXuehao(int xuehao) {
this.xuehao = xuehao;
}
public int getYingyu() {
return yingyu;
}
public void setYingyu(int yingyu) {
this.yingyu = yingyu;
}
public int getYuwen() {
return yuwen;
}
public void setYuwen(int yuwen) {
this.yuwen = yuwen;
}
public int average(int x,int y,int z){
return (x+y+z)/3;
}
}
这是测试类:
public class TestStudent{
public static void main(String args[]) {
Student st1=new Student();
st1.setShuxue(75);
st1.setYingyu(80);
st1.setYuwen(85);
System.out.println("第一个学生的平均成绩为:"+st1.average(st1.getShuxue(),st1.getYingyu(),st1.getYuwen()));
Student st2=new Student();
Student st3=new Student();
Student st4=new Student();
Student st5=new Student();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询