IT/Programming / / 2023. 4. 21. 17:31

[JAVA] 출판사 책 관리 - 클래스 활용 예제

반응형
package dayday11;

public class book {
	private String bookName;
	private String publisher;
	private int price;
	public String getBookName() {
		return bookName;
	}
	public void setBookName(String bookName) {
		this.bookName = bookName;
	}
	public String getPublisher() {
		return publisher;
	}
	public void setPublisher(String publisher) {
		this.publisher = publisher;
	}
	public int getPrice() {
		return price;
	}
	public void setPrice(int price) {
		this.price = price;
	}
	protected String showInfo(){
		return "";
	}
}

class Novel extends book {
	private String auther;
	public String getAuther() {
		return auther;
	}

	public void setAuther(String auther) {
		this.auther = auther;
	}
	public String showInfo(){
		return "책이름 : " + super.getBookName()+"\n"+
				"출판사 : " + super.getPublisher()+"\n"+
				"가격 : " + super.getPrice()+"\n"+
				"저자 : " + this.getAuther()+"\n";
	}
}

class TextBook extends book {
	private String subject;
	private int page;
	public String getSubject() {
		return subject;
	}
	public void setSubject(String subject) {
		this.subject = subject;
	}
	public int getPage() {
		return page;
	}
	public void setPage(int page) {
		this.page = page;
	}
	public String showInfo(){
		return "책이름 : " + super.getBookName()+"\n"+
				"출판사 : " + super.getPublisher()+"\n"+
				"가격 : " + super.getPrice()+"\n"+
				"과목 : " + this.getSubject()+"\n"+
				"페이지수 : " + this.getPage()+"\n";
	}
}


class Dictionary extends book {
	private String nation;
	private int word;
	public String getNation() {
		return nation;
	}
	public void setNation(String nation) {
		this.nation = nation;
	}
	public int getWord() {
		return word;
	}
	public void setWord(int word) {
		this.word = word;
	}
	public String showInfo(){
		return "책이름 : " + super.getBookName()+"\n"+
				"출판사 : " + super.getPublisher()+"\n"+
				"가격 : " + super.getPrice()+"\n"+
				"국가 : " + this.getNation()+"\n"+
				"단어 수 : " + this.getWord()+"\n";
	}
}

 


 

package dayday11;

import javax.swing.JOptionPane;
/* (클래스의 모든 멤버를 private로 getset, )
 * 부모클래스 : book
 * 	- 책이름
 *  - 출판사
 *  - 가격..
 *  - showInfo() : 메소드 중에서 모든 정보를 스트링으로 리턴
 *  
 * 자식클래스
 *  1) novel
 *   - 책이름, 출판사, 가격, 저자
 *  2) Textbook
 *   - 책이름, 출판사, 가격, 과목, 페이지 수
 *  3) dictionary
 *   - 책이름, 출판사, 가격, 국가, 단어 수 
 *  
 * 
 */
public class test01 {
	public static void main(String[] args) {

		Novel n = new Novel();
		TextBook t = new TextBook();
		Dictionary d = new Dictionary();
		
		while (true) {
			String tmp = "1. 소설책\n2. 텍스트 등록\n3. 사전 등록\n4. 보기\n5. 종료\n";
			tmp = JOptionPane.showInputDialog(tmp);
			if(tmp.equals("1")){
				tmp = JOptionPane.showInputDialog("소설책 이름을 지정해주세요");
				
				n.setBookName(tmp);
				tmp = JOptionPane.showInputDialog("출판사 이름을 지정해주세요");
				n.setPublisher(tmp);
				tmp = JOptionPane.showInputDialog("가격을(숫자) 지정해주세요");
				n.setPrice(Integer.parseInt(tmp));
				tmp = JOptionPane.showInputDialog("저자 이름을 지정해주세요");
				n.setAuther(tmp);
			}else if(tmp.equals("2")){
				tmp = JOptionPane.showInputDialog("택스트책 이름을 지정해주세요");
				
				t.setBookName(tmp);
				tmp = JOptionPane.showInputDialog("출판사 이름을 지정해주세요");
				t.setPublisher(tmp);
				tmp = JOptionPane.showInputDialog("가격을(숫자)  지정해주세요");
				t.setPrice(Integer.parseInt(tmp));
				tmp = JOptionPane.showInputDialog("과목 이름을 지정해주세요");
				t.setSubject(tmp);
				tmp = JOptionPane.showInputDialog("페이지 수(숫자) 지정해주세요");
				t.setPage(Integer.parseInt(tmp));
			}else if(tmp.equals("3")){
				tmp = JOptionPane.showInputDialog("사전 이름을 지정해주세요");
				
				d.setBookName(tmp);
				tmp = JOptionPane.showInputDialog("출판사 이름을 지정해주세요");
				d.setPublisher(tmp);
				tmp = JOptionPane.showInputDialog("가격을(숫자)  지정해주세요");
				d.setPrice(Integer.parseInt(tmp));
				tmp = JOptionPane.showInputDialog("국가 이름을 지정해주세요");
				d.setNation(tmp);
				tmp = JOptionPane.showInputDialog("단어 수(숫자) 지정해주세요");
				d.setWord(Integer.parseInt(tmp));
			}else if(tmp.equals("4")){
				if(n == null && t == null && d == null) JOptionPane.showMessageDialog(null, "아무것도 입력 하시지 않았습니다.");
				else {
					String mess =
							"///////////소설책///////////\n"+
							"소설 책 이름 : "+n.getBookName()+"\n"+
							"소설 출판사 이름 : "+n.getPublisher()+"\n"+
							"소설 가격 : "+n.getPrice()+"\n"+
							"소설 저자 : "+n.getAuther()+"\n"+
							"////////////////////////////\n\n"+
							"///////////텍스트 책///////////\n"+
							"텍스트 책 이름 : "+t.getBookName()+"\n"+
							"텍스트 책 출판사 이름 : "+t.getPublisher()+"\n"+
							"텍스트 책 가격 : "+t.getPrice()+"\n"+
							"텍스트 책 과목 : "+t.getSubject()+"\n"+
							"텍스트 책 페이지 수: "+t.getPage()+"\n"+
							"////////////////////////////\n\n"+
							"///////////사  전///////////\n"+
							"사  전 이름 : "+d.getBookName()+"\n"+
							"사  전 출판사 이름 : "+d.getPublisher()+"\n"+
							"사  전 가격 : "+d.getPrice()+"\n"+
							"사  전 작성 언어 : "+d.getNation()+"\n"+
							"사  전 단어 수 : "+d.getWord()+"\n"+
							"////////////////////////////\n"
							;
					JOptionPane.showMessageDialog(null, mess);
				}
				
			}else if(tmp.equals("5")) return;
		}
	}
}
반응형
  • 네이버 블로그 공유
  • 네이버 밴드 공유
  • 페이스북 공유
  • 카카오스토리 공유