用java写程序,定义一个student类,包含成员变量有学号、姓名、性别、班干部否、数学、语文?
1个回答
展开全部
public class Student {
/**
* @param args
*/
boolean master; //定义成员变量
int num;
String name,sex;
double math,chinese,english,score=0.0,average=0.0;
Student(int num,String name, String sex, boolean ma, double math, double chinese, double english ){ //构造方法
this.num = num;
this.name = name;
this.sex = sex;
this.master = ma;
this.math = math;
this.chinese = chinese;
this.english = english;
}
void score(){ //计算总分方法
score= math+chinese+english;
System.out.println(score);
}
void ave(){ //计算平均分方法
average = score/3;
System.out.println(average);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Student s = new Student(101,"kit","male",true,90.0,90.0,90.0); //创建对象
s.score(); //调用方法
s.ave();
}
}
/**
* @param args
*/
boolean master; //定义成员变量
int num;
String name,sex;
double math,chinese,english,score=0.0,average=0.0;
Student(int num,String name, String sex, boolean ma, double math, double chinese, double english ){ //构造方法
this.num = num;
this.name = name;
this.sex = sex;
this.master = ma;
this.math = math;
this.chinese = chinese;
this.english = english;
}
void score(){ //计算总分方法
score= math+chinese+english;
System.out.println(score);
}
void ave(){ //计算平均分方法
average = score/3;
System.out.println(average);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Student s = new Student(101,"kit","male",true,90.0,90.0,90.0); //创建对象
s.score(); //调用方法
s.ave();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询