1 changed files with 39 additions and 0 deletions
@ -0,0 +1,39 @@ |
|||
// 1. 定义 Student 类
|
|||
class Student { |
|||
private String studentId; |
|||
private String name; |
|||
private double score; |
|||
public Student(String studentId, String name, double score) { |
|||
this.studentId = studentId; |
|||
this.name = name; |
|||
this.score = score; |
|||
} |
|||
|
|||
public void study() { |
|||
System.out.println("学生 " + name + " (学号: " + studentId + ") 正在努力学习!"); |
|||
System.out.println("他/她的当前分数是: " + score); |
|||
} |
|||
|
|||
public String getStudentId() { return studentId; } |
|||
public String getName() { return name; } |
|||
public double getScore() { return score; } |
|||
|
|||
public void setScore(double score) { this.score = score; } |
|||
} |
|||
|
|||
public class StudentPractice { |
|||
public static void main(String[] args) { |
|||
Student student1 = new Student("S001", "张三", 88.5); |
|||
Student student2 = new Student("S002", "李四", 92.0); |
|||
|
|||
System.out.println("--- 第一个学生的学习情况 ---"); |
|||
student1.study(); |
|||
|
|||
System.out.println("\n--- 第二个学生的学习情况 ---"); |
|||
student2.study(); |
|||
|
|||
System.out.println("\n--- 李四经过努力后 ---"); |
|||
student2.setScore(95.0); |
|||
student2.study(); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue