用java设计一个学生类,学生信息有身份证号、学号、专业、姓名、性别、年龄及数学、英语、java程序设计三门课程的成绩。创建学生类的对象并输出对象的信息
时间: 2023-07-04 15:04:36 浏览: 1870
下面是一个示例代码,仅供参考:
```java
public class Student {
private String idCardNumber;
private String studentNumber;
private String major;
private String name;
private String gender;
private int age;
private double mathScore;
private double englishScore;
private double javaScore;
public Student(String idCardNumber, String studentNumber, String major, String name, String gender, int age,
double mathScore, double englishScore, double javaScore) {
this.idCardNumber = idCardNumber;
this.studentNumber = studentNumber;
this.major = major;
this.name = name;
this.gender = gender;
this.age = age;
this.mathScore = mathScore;
this.englishScore = englishScore;
this.javaScore = javaScore;
}
public String getIdCardNumber() {
return idCardNumber;
}
public void setIdCardNumber(String idCardNumber) {
this.idCardNumber = idCardNumber;
}
public String getStudentNumber() {
return studentNumber;
}
public void setStudentNumber(String studentNumber) {
this.studentNumber = studentNumber;
}
public String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public double getMathScore() {
return mathScore;
}
public void setMathScore(double mathScore) {
this.mathScore = mathScore;
}
public double getEnglishScore() {
return englishScore;
}
public void setEnglishScore(double englishScore) {
this.englishScore = englishScore;
}
public double getJavaScore() {
return javaScore;
}
public void setJavaScore(double javaScore) {
this.javaScore = javaScore;
}
public void printInfo() {
System.out.println("身份证号:" + this.idCardNumber);
System.out.println("学号:" + this.studentNumber);
System.out.println("专业:" + this.major);
System.out.println("姓名:" + this.name);
System.out.println("性别:" + this.gender);
System.out.println("年龄:" + this.age);
System.out.println("数学成绩:" + this.mathScore);
System.out.println("英语成绩:" + this.englishScore);
System.out.println("Java程序设计成绩:" + this.javaScore);
}
}
```
然后我们可以创建一个 `Student` 对象,并输出其信息:
```java
public class Main {
public static void main(String[] args) {
Student student = new Student("123456789012345678", "20210101", "计算机科学与技术", "张三", "男", 20,
90.5, 88.0, 95.0);
student.printInfo();
}
}
```
输出结果如下:
```
身份证号:123456789012345678
学号:20210101
专业:计算机科学与技术
姓名:张三
性别:男
年龄:20
数学成绩:90.5
英语成绩:88.0
Java程序设计成绩:95.0
```
阅读全文