Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.68 KB | None | 0 0
  1.  
  2. package bookdemo;
  3. public class Book {
  4.  private String title, author, publisher;
  5.  
  6.  public Book(){
  7.      title = "";
  8.      author = "";
  9.      publisher = "";
  10.  }
  11.   public Book(String t, String a, String p){
  12.      title = t;
  13.      author = a;
  14.      publisher = p;
  15.   }
  16.  public void setTitle(String t){
  17.        title = t;
  18.    }
  19.   public void setAuthor(String a){
  20.        author = a;
  21.    }
  22.    public void setPublisher(String p){
  23.        publisher = p;
  24.    }
  25.    public String getTitle(){
  26.        return title;
  27.    }
  28.    public String getAuthor(){
  29.        return author;
  30.    }
  31.    public String getPublisher(){
  32.        return publisher;
  33.    }
  34.    
  35. package bookdemo;
  36. import java.util.Scanner;
  37.  
  38. public class BookDemo {
  39.  
  40.     public static void main(String[] args) {
  41.         Book book1 = new Book("Starting Out with Java", "Tony Gaddis", "Pearson");
  42.         Book book2 = new Book();
  43.          
  44.          Scanner book = new Scanner(System.in);
  45.                  
  46.          System.out.println("Enter the Title: ");
  47.          String title = book.nextLine();
  48.          
  49.          System.out.println("Enter the Author: ");
  50.          String author = book.nextLine();
  51.        
  52.          System.out.println("Enter the Publisher: ");
  53.          String publisher = book.nextLine();
  54.          
  55.          book2.setTitle(title);
  56.          book2.setAuthor(author);
  57.          book2.setPublisher(publisher);
  58.          
  59.          System.out.println("Your book is " +book1.getTitle() + " by " +book1.getAuthor()+", published by " + book1.getPublisher());
  60.          System.out.println("Your book is " +book2.getTitle() + " by " +book2.getAuthor()+", published by " + book2.getPublisher());
  61.          
  62.          
  63.     }
  64.    
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement