永发信息网

Java编程需解答

答案:2  悬赏:60  手机版
解决时间 2021-01-14 02:48
  • 提问者网友:遮云壑
  • 2021-01-13 17:35
Java编程需解答
最佳答案
  • 五星知识达人网友:从此江山别
  • 2021-01-13 19:07
import java.util.Scanner;
public class Demo1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
Student[] stu = new Student[3];
for (int i = 0; i < stu.length; i++) {
System.out.println("请输入"+(i+1)+"学生的学号");
int id =input.nextInt();
System.out.println("请输入"+(i+1)+"学生的姓名");
String name = input.next();
System.out.println("请输入"+(i+1)+"学生的第一门课成绩");
double score1 =input.nextDouble();
System.out.println("请输入"+(i+1)+"学生的第二门课成绩");
double score2 =input.nextDouble();
System.out.println("请输入"+(i+1)+"学生的第三门课成绩");
double score3 =input.nextDouble();
Student s = new Student(id, name, score1,score2,score3);
stu[i]=s;
}
for (Student s : stu) {
System.out.println(s);
}
}
}
class Student{
private int id;
private String name;
private double score;
private double score1;
private double score2;
private double score3;
public Student() {
super();
}
public Student(int id, String name, double score1, double score2,
double score3) {
super();
this.id = id;
this.name = name;
this.score1 = score1;
this.score2 = score2;
this.score3 = score3;
}
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;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getScore() {
score = (getScore1()+getScore2()+getScore3())/3;
return score;
}
public String toString() {
return "学号=" + id + ", 姓名=" + name + ", 平均成绩=" + getScore();
}
}
全部回答
  • 1楼网友:西岸风
  • 2021-01-13 19:46
又来?一样的?追答刚写了一个一样的,不知道你是不是同一个人。需要可以发你
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯