From 623b7cc16a7d8477820ca84799b69d715240ee7c Mon Sep 17 00:00:00 2001 From: t-eguchi <26-t-eguchi-tmn@it-college.co.jp> Date: Tue, 15 Sep 2026 15:46:57 +0900 Subject: [PATCH] =?UTF-8?q?=EF=BC=93=E6=AE=B5=E9=9A=8E=E7=9B=AE=E7=B5=82?= =?UTF-8?q?=E3=82=8F=E3=82=8A=E3=81=BE=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- em-oop/src/BasicCheck2.java | 21 +++++++++++++++++---- em-oop/src/Student.java | 15 ++++++++++++++- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/em-oop/src/BasicCheck2.java b/em-oop/src/BasicCheck2.java index 3b5dbbc..1f7b0ab 100644 --- a/em-oop/src/BasicCheck2.java +++ b/em-oop/src/BasicCheck2.java @@ -1,10 +1,23 @@ public class BasicCheck2 { public static void main(String[] args) { - Student student = new Student(); - student.studentId = 1; - student.name = "鈴木一郎"; - student.printProfile(); + + Student student1 = new Student(1, "鈴木一郎"); + Student student2 = new Student(2, "田中花子"); + Student student3 = new Student(3, "佐藤次郎"); + + student1.printProfile(); + student2.printProfile(); + student3.printProfile(); + + + Student.getStudentCount(); + System.out.println("現在の生徒数:" + Student.getStudentCount() + "人"); + + } + + + } \ No newline at end of file diff --git a/em-oop/src/Student.java b/em-oop/src/Student.java index 436c2f0..c01c443 100644 --- a/em-oop/src/Student.java +++ b/em-oop/src/Student.java @@ -3,9 +3,22 @@ public class Student { int studentId; String name; + static int studentCount = 0; + public void printProfile () { - System.out.println("学籍番号:" + this.studentId + " 名前 " + this.name); + System.out.println("学籍番号:" + this.studentId + " 名前:" + this.name); } + public Student(int studentId, String name) { + this.studentId = studentId; + this.name = name; + studentCount++; + } + + static int getStudentCount() { + return studentCount; + } + + }