public class Student {
private String No;
private String name;
private String sex;
private double score;
public Student(String no, String name, String sex, double score) {
super();
No = no;
this.name = name;
this.sex = sex;
this.score = score;
}
public String getNo() {
return No;
}
public String getName() {
return name;
}
public String getSex() {
return sex;
}
public double getScore() {
return score;
}
public void changeScore(double score){
this.score = score;
}
public void display(){
System.out.println("[学号 ] : " + this.getNo()
+ ". [姓名] : " + this.getName()
+ ". [性别] : " + this.getSex()
+ ". [成绩] : " + this.getScore());
}
public static void main(String[] args) {
Student s1 = new Student("120", "张三", "男", 86.5);
Student s2 = new Student("123", "李四", "男", 90.0);
//输出学生信息
s1.display();
s2.display();
//输出平均值
System.out.println("两个学生的平均值是:" + (s1.getScore() + s2.getScore()) / 2);
}
}
在MyEclipse 10下调试通过
public class Student {
private String num;
private String name;
private String sex;
private double score;
public String getNum() {
return num;
}
public String getName() {
return name;
}
public double getScore() {
return score;
}
public String getSex() {
return sex;
}
public double changescore(double score)
{
this.score=score;
return score;
}
public Student(String name,String num,String sex,double score)
{
this.name = name;
this.num=num;
this.sex=sex;
this.score=score;
}
@Override
public String toString() {
return "Name: "+name+" Num: "+num+" Sex: "+sex+" Score: "+score;
}
public static void main(String[] args) {
Student s1 = new Student("Tom","020203","Male",94.50);
Student s2 = new Student("Jerry","020308","Female",82.00);
double avg = (s1.score+s2.score)/(2.0);
System.out.println(s1);
System.out.println(s2);
System.out.println("Tom and Jerry average score is "+avg);
}
}
运行结果如下:
怎么发给你