2日目_段階1_完了

This commit is contained in:
2026-09-15 14:36:27 +09:00
parent 7559a7dfa7
commit c82f9ca678
6 changed files with 65 additions and 24 deletions

View File

@@ -3,17 +3,22 @@ public class BasicCheck1 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
Book book = new Book(); // Book book = new Book();
book.title = "吾輩は猫である"; // book.title = "吾輩は猫である";
book.author ="夏目漱石"; // book.author ="夏目漱石";
book.price = 800; // book.price = 800;
System.out.println(book.title); Book book1 = new Book();
System.out.println(book.author);
System.out.println(book.price);
System.out.println(book1.title);
System.out.println(book1.author);
System.out.println(book1.price);
Book book2 = new Book("銀河鉄道の夜","宮沢賢治", 500);
System.out.println(book2.title);
System.out.println(book2.author);
System.out.println(book2.price);
} }

View File

@@ -1,11 +1,11 @@
public class BasicCheck2 { public class BasicCheck2 {
public static void main(String[] args) { public static void main(String[] args) {
Student student = new Student(1,"鈴木一郎"); Student student = new Student();
//
student.studentId = 1; student.studentId = 1;
student.name = "鈴木一郎"; student.name = "鈴木一郎";
//
// System.out.print("学籍番号"+student.studentId); // System.out.print("学籍番号"+student.studentId);
// System.out.print("名前:" + student.name); // System.out.print("名前:" + student.name);
student.printProfile(); student.printProfile();

View File

@@ -0,0 +1,8 @@
public class BasicCheck3 {
public static void main() {
Item[] items = new Item[3];
}
}

View File

@@ -1,7 +1,24 @@
public class Book { public class Book {
String title; public String title;
String author; public String author;
int price; public int price;
//引数なしコンストラクタ
public Book() {
this.title = "タイトル未設定";
this.author = "著者未設定";
this.price = 0;
// System.out.println("コンストラクタが呼び出されました");
}
//引数ありコンストラクタ
public Book(String title, String author, int price) {
// System.out.println("引数なしのコンストラクタが呼び出されました");
this.title = title;
this.author = author;
this.price = price;
}
} }

11
em-oop/src/Item.java Normal file
View File

@@ -0,0 +1,11 @@
public class Item {
String name;
int price;
int stock;
public void sell(int amount) {
this.stock = this.stock - amount;
}
}

View File

@@ -1,22 +1,22 @@
public class Student { public class Student {
int studentId; int studentId;
String name; String name;
public Student(int studentId, String name) { // public Student(int studentId, String name) {
this.studentId = studentId; // this.studentId = studentId;
this.name = name; // this.name;
}
public void printProfile() { void printProfile() {
System.out.println("学籍番号:" + this.studentId + " 名前:" + this.name); System.out.println("学籍番号:" + this.studentId + " 名前:" + this.name);
} }
public static void main(String[] args) { // public static void main(String[] args) {
Student s = new Student(1,"鈴木一郎"); // Student s = new Student(1,"鈴木一郎");
s.printProfile(); // s.printProfile();
//
} }
}