2日目_段階1_完了
This commit is contained in:
@@ -3,17 +3,22 @@ public class BasicCheck1 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
Book book = new Book();
|
||||
book.title = "吾輩は猫である";
|
||||
book.author ="夏目漱石";
|
||||
book.price = 800;
|
||||
// Book book = new Book();
|
||||
// book.title = "吾輩は猫である";
|
||||
// book.author ="夏目漱石";
|
||||
// book.price = 800;
|
||||
|
||||
System.out.println(book.title);
|
||||
System.out.println(book.author);
|
||||
System.out.println(book.price);
|
||||
Book book1 = new Book();
|
||||
|
||||
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);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
|
||||
public class BasicCheck2 {
|
||||
public static void main(String[] args) {
|
||||
Student student = new Student(1,"鈴木一郎");
|
||||
|
||||
Student student = new Student();
|
||||
//
|
||||
student.studentId = 1;
|
||||
student.name = "鈴木一郎";
|
||||
|
||||
//
|
||||
// System.out.print("学籍番号"+student.studentId);
|
||||
// System.out.print("名前:" + student.name);
|
||||
student.printProfile();
|
||||
|
||||
8
em-oop/src/BasicCheck3.java
Normal file
8
em-oop/src/BasicCheck3.java
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
public class BasicCheck3 {
|
||||
public static void main() {
|
||||
Item[] items = new Item[3];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,24 @@
|
||||
|
||||
public class Book {
|
||||
String title;
|
||||
String author;
|
||||
int price;
|
||||
public String title;
|
||||
public String author;
|
||||
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
11
em-oop/src/Item.java
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
public class Item {
|
||||
String name;
|
||||
int price;
|
||||
int stock;
|
||||
|
||||
public void sell(int amount) {
|
||||
this.stock = this.stock - amount;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,22 +1,22 @@
|
||||
|
||||
public class Student {
|
||||
|
||||
int studentId;
|
||||
String name;
|
||||
|
||||
public Student(int studentId, String name) {
|
||||
this.studentId = studentId;
|
||||
this.name = name;
|
||||
}
|
||||
// public Student(int studentId, String name) {
|
||||
// this.studentId = studentId;
|
||||
// this.name;
|
||||
|
||||
public void printProfile() {
|
||||
void printProfile() {
|
||||
System.out.println("学籍番号:" + this.studentId + " 名前:" + this.name);
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
Student s = new Student(1,"鈴木一郎");
|
||||
s.printProfile();
|
||||
|
||||
// public static void main(String[] args) {
|
||||
// Student s = new Student(1,"鈴木一郎");
|
||||
// s.printProfile();
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user