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

2024年11月27日 15:29
有1个网友回答
网友(1):

class Student
{
int number;
String name,sex;
Boolean master;
double math,chinese,english,score=0.0,average=0.0;

public Student(int num,String name,String sex,Boolean ma,double math,double chinese,double english){
this.number=num;
this.name=name;
this.sex=sex;
this.master=ma;
this.math=math;
this.chinese=chinese;
this.english=english;
}

double score(){

return math+chinese+english;
}
double ave(){
return score()/3;
}
}
public class xuesheng
{
public static void main(String[] args)
{
Student s=new Student(101,"kimi","man",true,90.0,90.0,90.0);

System.out.println("总分:"+s.score());
System.out.println("平均:"+s.ave());
}

}