package org.joonzis.ex;
/*
* 필드
* - String title : 책 제목
* - String writer : 저자
* - int price : 책 가격
* - int salesVolume : 판매량
* - boolean isBestSeller : 베스트 셀러 유무
*
* 메소드
* - 생성자()
* - 생성자() : 제목, 가격 초기화 (저자는 "작자미상" 으로 기입)
* - 생성자() : 제목, 가격, 저자 초기화
* - setSalesVolume(int sales) : 판매량이 1000 이상이면 베스트 셀러
* - output() : 제목, 저자, 가격, 판매량, 베스트셀러 유무 출력
*/
public class Ex04_Book {
String title;
String writer;
int price;
int salesVolume;
boolean isBestSeller;
public Ex04_Book() {}
public Ex04_Book(String _title, int _price) {
title = _title;
price = _price;
writer = "작자미상";
}
public Ex04_Book(String _title, int _price, String _writer) {
title = _title;
price = _price;
writer = _writer;
}
void setSalesVolume(int sales) {
salesVolume = sales;
if(salesVolume >= 1000) {
isBestSeller = true;
}else {
isBestSeller = false;
}
}
void output() {
System.out.println("책 제목 : " + title);
System.out.println("책 가격 : " + price);
System.out.println("책 저자 : " + writer);
System.out.println("책 판매량 : " + salesVolume);
System.out.println(isBestSeller ? "베스트셀러" : "일반서적");
}
}
package org.joonzis.ex;
public class Ex04_BookMain {
public static void main(String[] args) {
Ex04_Book b1 = new Ex04_Book();
Ex04_Book b2 = new Ex04_Book("기적의 집밥책", 18000);
Ex04_Book b3 = new Ex04_Book("김밀란 리조또", 18000, "김밀란");
b1.setSalesVolume(0);
b2.setSalesVolume(500);
b3.setSalesVolume(2000);
b1.output();
System.out.println("--------------------");
b2.output();
System.out.println("--------------------");
b3.output();
}
}