반응형

books.java



package HashMap;

// 책의 이름과  장르 가격을 지정하는 클래스
public class books {
	
	private String title;
	private String jang;
	private int price;
	
	
	public books() {
		super();
	}


	public books(String title, String jang, int price) {
		super();
		this.title = title;
		this.jang = jang;
		this.price = price;
	}


	public String getTitle() {
		return title;
	}


	public void setTitle(String title) {
		this.title = title;
	}


	public String getJang() {
		return jang;
	}


	public void setJang(String jang) {
		this.jang = jang;
	}


	public int getPrice() {
		return price;
	}


	public void setPrice(int price) {
		this.price = price;
	}


	@Override
	public String toString() {
		return "books [title=" + title + ", jang=" + jang + ", price=" + price
				+ "]";
	}
	
	
	

}



BookMain1.java


package HashMap;

import java.util.*;

public class BookMain1 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		books obj1 = new books();
		
		obj1.setTitle("Java 프로그래밍");
		obj1.setJang("컴퓨터");
		obj1.setPrice(37000);
		
		System.out.println("책 제목 : " + obj1.getTitle());
		System.out.println("장 르 : " + obj1.getJang());
		System.out.println("가 격  : " + obj1.getPrice());
		
		HashMap book = 
				new HashMap();
		
		book.put("책 제목", "Don't worry Be happy");
		book.put("장 르", "romance");
		book.put("가 격", "45000");
		
		Setset = book.keySet();
		for(String key : set){
			System.out.println(key+" : " + book.get(key));
		}
	}
}



+ Recent posts