java 设计一个学生类

2024-11-27 22:33:19
推荐回答(5个)
回答(1):

class Strudent{
private int no;
private String name;
private float grade;
static float sum=0f;
static int num=0;
Student(int n,String na,float d){
this.no=n;
this.name=na;
this.grade=d;
num++;//人数累加
sum=sum+d;//分数累加
}
public float average(){

return this.sum/this.num;
}
public void display(){

System.out.println("学号:"+this.no);
System.out.println("姓名:"+this.name);
System.out.println("成绩:"+this.grade);

}

}

class SomeStudents{
public void static main(String[] args){
Student st1=new Studnet(20100001,"张三",100f);
st1.display();
Student st2=new Studnet(20100002,"李四",50f);
st2.display();
float av=st2.average();
System.out.println("平均分为:"+av);//或得以上2人平均成绩
}

}

回答(2):

public class Student {
String name;
int age;
String sex;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
@Override
public String toString() {
return "Student [name=" + name + ", age=" + age + ", sex=" + sex + "]";
}

回答(3):

class Student{
String name;
int age;
int grade;
}
public class StudentTest{
public static void main(String[] args){
Student Mike = new Student();
Mike.name = "mike";
Mike.age = 10;
Mike.grade = 5;
}
}

回答(4):

创建一个学生的实体类????

回答(5):

要包含哪些属性呢