用JAVA设计一个学生类(以自己为参照物)。学生信息有身份证号、学号、专业、姓名、性别、年龄及离散数学、数据结构和Java程序设计3门课程的成绩。创建信息类的对象并输出对象的信息。
时间: 2023-08-07 22:08:19 浏览: 62
好的,以下是一个用JAVA设计的学生类,包括学生的基本信息和成绩信息:
```java
public class Student {
private String id; // 身份证号
private String stuNo; // 学号
private String major; // 专业
private String name; // 姓名
private String gender; // 性别
private int age; // 年龄
private double mathScore; // 离散数学成绩
private double dsScore; // 数据结构成绩
private double javaScore; // Java程序设计成绩
public Student(String id, String stuNo, String major, String name, String gender, int age, double mathScore, double dsScore, double javaScore) {
this.id = id;
this.stuNo = stuNo;
this.major = major;
this.name = name;
this.gender = gender;
this.age = age;
this.mathScore = mathScore;
this.dsScore = dsScore;
this.javaScore = javaScore;
}
public String getId() {
return id;
}
public String getStuNo() {
return stuNo;
}
public String getMajor() {
return major;
}
public String getName() {
return name;
}
public String getGender() {
return gender;
}
public int getAge() {
return age;
}
public double getMathScore() {
return mathScore;
}
public double getDsScore() {
return dsScore;
}
public double getJavaScore() {
return javaScore;
}
public void setId(String id) {
this.id = id;
}
public void setStuNo(String stuNo) {
this.stuNo = stuNo;
}
public void setMajor(String major) {
this.major = major;
}
public void setName(String name) {
this.name = name;
}
public void setGender(String gender) {
this.gender = gender;
}
public void setAge(int age) {
this.age = age;
}
public void setMathScore(double mathScore) {
this.mathScore = mathScore;
}
public void setDsScore(double dsScore) {
this.dsScore = dsScore;
}
public void setJavaScore(double javaScore) {
this.javaScore = javaScore;
}
public double getAverageScore() {
return (mathScore + dsScore + javaScore) / 3;
}
public static void main(String[] args) {
Student s = new Student("1234567890", "20210001", "计算机科学与技术", "张三", "男", 20, 90, 85, 95);
System.out.println("姓名:" + s.getName());
System.out.println("性别:" + s.getGender());
System.out.println("年龄:" + s.getAge());
System.out.println("身份证号:" + s.getId());
System.out.println("学号:" + s.getStuNo());
System.out.println("专业:" + s.getMajor());
System.out.println("离散数学成绩:" + s.getMathScore());
System.out.println("数据结构成绩:" + s.getDsScore());
System.out.println("Java程序设计成绩:" + s.getJavaScore());
System.out.println("平均成绩:" + s.getAverageScore());
}
}
```
在这个学生类中,我们定义了学生的基本信息和成绩信息,并提供了相应的 get 和 set 方法。其中,getAverageScore() 方法用于计算学生的三门课程的平均成绩。
在 main() 方法中,我们创建了一个学生对象 s,并输出了学生的基本信息和成绩信息。
希望这个代码能够对你有所帮助!
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)