发布网友 发布时间:2023-11-10 04:27
共4个回答
热心网友 时间:2024-12-12 11:15
追问2.定义一个表示学生的类(Student)。Student类包括表示学生的学号,姓名,班级,3门课程成绩的信息数据及用来获得和设置学号,姓名,班级和3门课程成绩的方法,创建TestStudent类,在TestStudent中生成2个学生对象,计算3门课程的平均成绩并输出。追答刚给你截了几个图,不知道你看不看得到
测试笔记本类:
public class TestComputer {
public static void main(String[] args) {
Computer c = new Computer("blue", "586");
c.display();
}
}
学生类:
public class Student {
private String num; private String name;//姓名
private String cla; private int s1;//1门课程成绩
private int s2;private int s3;//3门课程成绩
public String getNum() {
return num;}
public void setNum(String num) {
this.num = num;}
public String getName() {
return name;}
public void setName(String name) {
this.name = name;}
public String getCla() {
return cla;}
public void setCla(String cla) {
this.cla = cla;}
public int getS1() {
return s1;}
public void setS1(int s1) {
this.s1 = s1;}
public int getS2() {
return s2;}
public void setS2(int s2) {
this.s2 = s2;}
public int getS3() {
return s3;}
public void setS3(int s3) {
this.s3 = s3;}
}
测试学生类:
public class TestStudent {
public static void main(String[] args) {
Student st1 = new Student();
st1.setNum("1");
st1.setName("1");
st1.setCla("1");
st1.setS1(1);
st1.setS2(1);
st1.setS3(1);
Student st2 = new Student();
st2.setNum("2");
st2.setName("2");
st2.setCla("2");
st2.setS1(2);
st2.setS2(2);
st2.setS3(2);
System.out.println((st1.getS1()+st1.getS2()+st1.getS3())/3);
System.out.println((st2.getS1()+st2.getS2()+st2.getS3())/3);
}
}
热心网友 时间:2024-12-12 11:16
第一题代码如下:热心网友 时间:2024-12-12 11:16
/*********************************热心网友 时间:2024-12-12 11:17
public class Computer {