2日目 段階3 小澤

This commit is contained in:
2026-09-15 15:28:32 +09:00
parent a3ddbaed43
commit 1abebc37e0
2 changed files with 29 additions and 7 deletions

View File

@@ -1,12 +1,21 @@
public class BasicCheck2 { public class BasicCheck2 {
public static void main(String[] args) { 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; student1.printProfile();
student.name = "鈴木一郎"; student2.printProfile();
student3.printProfile();
student.printProfile(); System.out.println("現在の生徒数:"+Student.getStudentCount()+"人");
// student.studentId = 1;
// student.name = "鈴木一郎";
//
// student.printProfile();
} }
} }

View File

@@ -2,10 +2,23 @@
public class Student { public class Student {
int studentId; int studentId;
String name; String name;
static int studentCount = 0;
public void printProfile() {
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++;
}
public static int getStudentCount() {
return studentCount;
}
} }