From c0fa932e1f16dcb268f0b2320a244f32f806783d Mon Sep 17 00:00:00 2001 From: GaoGeng <3123557312@qq.com> Date: Tue, 24 Mar 2026 13:55:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20'W2'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- W2/Student.java | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 W2/Student.java diff --git a/W2/Student.java b/W2/Student.java new file mode 100644 index 0000000..321edb5 --- /dev/null +++ b/W2/Student.java @@ -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(); + } +} \ No newline at end of file