Notice
Recent Posts
Recent Comments
Link
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

WON.dev

chapter04 : Book / BookMain 본문

JAVA/chapter15_access_modifer

chapter04 : Book / BookMain

GAWON 2023. 5. 26. 18:46
package org.joonzis.ex;

public class Ex04_Book {

	// Field
	private String title;
	private String writer;
	private int price;
	private int salesVolume;		// 판매량
	private boolean isBestSeller;	// 판매량이 1000 이상이면 true, 아니면 false
	
	// Constructor
	public Ex04_Book(){ }
	public Ex04_Book(String title, String writer, int price){
		this.title = title;
		this.writer = writer;
		this.price = price;
	}
	public Ex04_Book(String title,int price){
		this(title,"작자미상",price);
	}
	
	//  Method	
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getWriter() {
		return writer;
	}
	public void setWriter(String writer) {
		this.writer = writer;
	}
	public int getPrice() {
		return price;
	}
	public void setPrice(int price) {
		this.price = price;
	}
	public int getSalesVolume() {
		return salesVolume;
	}
	public void setSalesVolume(int salesVolume) {
		this.salesVolume = salesVolume;
		this.isBestSeller = (salesVolume >= 1000) ? true : false;
		// setBestSeller((salesVolume >= 1000) ? true : false); ↑ 이거랑 똑같음!
	}
	public boolean isBestSeller() {
		return isBestSeller;
	}
	public void setBestSeller(boolean isBestSeller) {
		this.isBestSeller = isBestSeller;
	}

	public void output() {
		System.out.println("제목 : " + title);
		System.out.println("저자 : " + writer);
		System.out.println("가격 : " + price);
		System.out.println("판매량 : " + salesVolume);
		System.out.println(isBestSeller ? "베스트셀러" : "일반서적");
	}
	
}
package org.joonzis.ex;

public class Ex04_BookMain {

	public static void main(String[] args) {
		
		Ex04_Book book1 = new Ex04_Book();
		Ex04_Book book2 = new Ex04_Book("오디션","천계영", 38000);
		Ex04_Book book3 = new Ex04_Book("콩쥐팥쥐", 5000);
		
		book1.setSalesVolume(0);
		book2.setSalesVolume(500);
		book3.setSalesVolume(1500);
		
		book1.output();
		System.out.println("---------------------");
		book2.output();
		System.out.println("---------------------");
		book3.output();

	}

}

'JAVA > chapter15_access_modifer' 카테고리의 다른 글

chapter06 : Local / LocalMain  (0) 2023.05.26
chapter05 : Circle / CircleMain  (0) 2023.05.26
chapter03 : person / personmain  (0) 2023.05.26
chapter02 : Student / StudentMain  (0) 2023.05.26
chapter01 : rect / rectmain  (0) 2023.05.26