Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package bookdemo;
- public class Book {
- private String title, author, publisher;
- public Book(){
- title = "";
- author = "";
- publisher = "";
- }
- public Book(String t, String a, String p){
- title = t;
- author = a;
- publisher = p;
- }
- public void setTitle(String t){
- title = t;
- }
- public void setAuthor(String a){
- author = a;
- }
- public void setPublisher(String p){
- publisher = p;
- }
- public String getTitle(){
- return title;
- }
- public String getAuthor(){
- return author;
- }
- public String getPublisher(){
- return publisher;
- }
- package bookdemo;
- import java.util.Scanner;
- public class BookDemo {
- public static void main(String[] args) {
- Book book1 = new Book("Starting Out with Java", "Tony Gaddis", "Pearson");
- Book book2 = new Book();
- Scanner book = new Scanner(System.in);
- System.out.println("Enter the Title: ");
- String title = book.nextLine();
- System.out.println("Enter the Author: ");
- String author = book.nextLine();
- System.out.println("Enter the Publisher: ");
- String publisher = book.nextLine();
- book2.setTitle(title);
- book2.setAuthor(author);
- book2.setPublisher(publisher);
- System.out.println("Your book is " +book1.getTitle() + " by " +book1.getAuthor()+", published by " + book1.getPublisher());
- System.out.println("Your book is " +book2.getTitle() + " by " +book2.getAuthor()+", published by " + book2.getPublisher());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement