用java写程序,定义一个student类,包含的内容如下。成员变量:学号、姓名、性别、班干部否、数学、语文、

2024-11-18 01:33:45
推荐回答(3个)
回答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();
}

}

回答2:

public class Student{
String number;
String name;
String sex;
boolean isLeader;
float math;
float yuwen;

public Student(String number,String name,String sex, boolean isLeader,
float math,float yuwen){
this.number=number;
this.....
....
}
}

回答3:

public class Student{
int studentId;
String Name;
String gender;
boolean isGender;
int manthScore;
int chaneseScore;
}