Java中用类与对象的思想写5个同学的成绩,要求有成绩 和平均分,然后依照平均分来分判断 优秀什么
答案:2 悬赏:0 手机版
解决时间 2021-02-06 21:08
- 提问者网友:龅牙恐龙妹
- 2021-02-06 07:58
Java中用类与对象的思想写5个同学的成绩,要求有成绩 和平均分,然后依照平均分来分判断 优秀什么,怎么做啊
最佳答案
- 五星知识达人网友:神也偏爱
- 2021-02-06 09:19
public class CStudent {
private String name;
private double score1;
private double score2;
private double score3;
public CStudent(String name ,double score1,
double score2, double score3) {
this.name = name;
this.score1 = score1;
this.score2 = score2;
this.score3 = score3;
}
public double getAvg(){
return (score1+score2+score3)/3;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getScore1() {
return score1;
}
public void setScore1(double score1) {
this.score1 = score1;
}
public double getScore2() {
return score2;
}
public void setScore2(double score2) {
this.score2 = score2;
}
public double getScore3() {
return score3;
}
public void setScore3(double score3) {
this.score3 = score3;
}
}
private String name;
private double score1;
private double score2;
private double score3;
public CStudent(String name ,double score1,
double score2, double score3) {
this.name = name;
this.score1 = score1;
this.score2 = score2;
this.score3 = score3;
}
public double getAvg(){
return (score1+score2+score3)/3;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getScore1() {
return score1;
}
public void setScore1(double score1) {
this.score1 = score1;
}
public double getScore2() {
return score2;
}
public void setScore2(double score2) {
this.score2 = score2;
}
public double getScore3() {
return score3;
}
public void setScore3(double score3) {
this.score3 = score3;
}
}
全部回答
- 1楼网友:人類模型
- 2021-02-06 09:30
public class demo {
private static int sum = 0;
private static int pingj = 0;
public static void main(string[] args) {
student s1 = new student(56);
student s2 = new student(65);
student s3 = new student(98);
student s4 = new student(23);
student s5 = new student(71);
sum = s1.toint()+s2.toint()+s3.toint()+s4.toint()+s5.toint();
pingj = sum / 5;
system.out.println(pingj);
}
}
class student{
private int chengji;
public student(int chengji) {
this.chengji = chengji;
}
public int toint() {
return this.chengji;
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯