JAVA

도서관 사서

코린이도이 2023. 9. 24. 17:49

1. Book의 인스턴스 b1, b2를 각각 생성하고 위 표의 있는 값을 Book의 매개 변수에 넣은 후 printInfo 메소드를 활용하여 출력하세요.

변수명 isbn author title publisher
b1 978-89-123456-0-1 William Shakespeare Hamlet Good Books
b2 978-89-234567-0-9 Miguel de Cervantes Don Quixote Literature World
class Book {
	String isbn;
    String author;
    String title;
    String publisher;
    
    void printInfo(){
    	System.out.println("ISBN : " + isbn + "\nauthor : " + author + "\ntitle : " + title + "\npublisher : " + publisher + "\n");
    }
    Book(String isbn, String author, String title, String publisher) {
    	this.isbn = isbn;
        this.author = author;
        this.title = title;
        this.publisher = publisher;
    }
}

public class Main {
	public static void main(String args[]) {
    	Book b1 = new Book("978-89-123456-0-1", "William Shakespeare","Hamlet", "Good Books");
        b1.printInfo();
        Book b2 = new Book("978-89-234567-0-9","Miguel de Cervantes", "Don Quixote", "Literature World");
        b2.printInfo();
    }
}