class Book {
String title;
int price;
public Book(String title, int price) {
this.title = title;
this.price = price;
}
@Override
public String toString() {
return title + "(" + price + ")";
}
}
class Bookcase {
String category;
Book[] books;
public Bookcase(String category, Book... books) {
this.category = category;
this.books = books;
}
@Override
public String toString() {
String info = "- category : " + category + "\n";
info += "- book list\n";
for(Book temp: books) {
info += "\t" + temp + "\n";
}
return info;
}
}
class Bookstore {
String name;
String tel;
Bookcase[] cases;
public Bookstore(String name, String tel, Bookcase...cases) {
this.name = name;
this.tel = tel;
this.cases = cases;
}
@Override
public String toString() {
String info = "<< " + name + " bookstore >>\n";
info += "- tel : " + tel + "\n";
for(Bookcase temp : cases) {
info += temp + "\n";
}
return info;
}
}
class BookCaseTest {
public static void main(String[] args) {
Bookcase case1 = new Bookcase(
"IT",
new Book("power java", 35000),
new Book("ultra java", 38000),
new Book("hyper java", 41000)
);
Bookcase case2 = new Bookcase(
"novel",
new Book("춘식이는 최고야", 35000),
new Book("춘식이는 집순이", 38000),
new Book("춘식이는 바보", 41000)
);
Bookstore store = new Bookstore("green", "051-900-1000", case1, case2);
System.out.println(store);
}
}
[결과값]
<< green bookstore >>
- tel : 051-900-1000
- category : IT
- book list
power java(35000)
ultra java(38000)
hyper java(41000)
- category : novel
- book list
춘식이는 최고야(35000)
춘식이는 집순이(38000)
춘식이는 바보(41000)