From 1abebc37e069f8f59470016868f58d469e8bf253 Mon Sep 17 00:00:00 2001 From: m_ozawa <26-m-ozawa-swnet@it-college.co.jp> Date: Tue, 15 Sep 2026 15:28:32 +0900 Subject: [PATCH] =?UTF-8?q?=EF=BC=92=E6=97=A5=E7=9B=AE=E3=80=80=E6=AE=B5?= =?UTF-8?q?=E9=9A=8E=EF=BC=93=E3=80=80=E5=B0=8F=E6=BE=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- em-oop/src/BasicCheck2.java | 17 +++++++++++++---- em-oop/src/Student.java | 19 ++++++++++++++++--- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/em-oop/src/BasicCheck2.java b/em-oop/src/BasicCheck2.java index e90d1a6..3f97067 100644 --- a/em-oop/src/BasicCheck2.java +++ b/em-oop/src/BasicCheck2.java @@ -1,12 +1,21 @@ public class BasicCheck2 { public static void main(String[] args) { - Student student = new Student(); + Student student1 = new Student(1, "鈴木一郎"); + Student student2 = new Student(2, "田中花子"); + Student student3 = new Student(3, "佐藤次郎"); - student.studentId = 1; - student.name = "鈴木一郎"; + student1.printProfile(); + student2.printProfile(); + student3.printProfile(); - student.printProfile(); + System.out.println("現在の生徒数:"+Student.getStudentCount()+"人"); + + +// student.studentId = 1; +// student.name = "鈴木一郎"; +// +// student.printProfile(); } } diff --git a/em-oop/src/Student.java b/em-oop/src/Student.java index a668753..8475b66 100644 --- a/em-oop/src/Student.java +++ b/em-oop/src/Student.java @@ -2,10 +2,23 @@ public class Student { int studentId; String name; - - public void printProfile() { + static int studentCount = 0; + + public void printProfile() { System.out.println("学籍番号:" + this.studentId + " 名前:" + this.name); - + } + public Student(int studentId, String name) { + this.studentId = studentId; + this.name = name; + studentCount++; + } + + public static int getStudentCount() { + return studentCount; + } + + + }