Advertisement
Guest User

Untitled

a guest
Jan 24th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.32 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package exam1retake;
  7.  
  8. /**
  9.  *
  10.  * @author localstudent
  11.  */
  12. public class Book {
  13.     String title;
  14.     String author;
  15.     int pages;
  16.  
  17.     public Book(String title, String author, int pages) {
  18.         setTitle(title);
  19.         setAuthor(author);
  20.         setPages(pages);
  21.     }
  22.    
  23.     public Book() {
  24.         this.title = "Title";
  25.         this.author = "Author";
  26.         this.pages = 10;
  27.     }
  28.    
  29.     public Book(Book book1) {
  30.         setTitle(book1.title);
  31.         setAuthor(book1.author);
  32.         setPages(book1.pages);
  33.     }
  34.    
  35.    
  36.  
  37.     public String getTitle() {
  38.         return title;
  39.     }
  40.    
  41.     public String getAuthor() {
  42.         return author;
  43.     }
  44.    
  45.     public int getPages() {
  46.         return pages;
  47.     }
  48.  
  49.     public void setTitle(String title) {
  50.         this.title = title;
  51.     }
  52.  
  53.     public void setAuthor(String author) {
  54.         this.author = author;
  55.     }
  56.  
  57.     public void setPages(int pages) {
  58.         this.pages = pages;
  59.     }
  60.    
  61.     @Override
  62.     public String toString() {
  63.         return String.format("Title: %s" + "Author: %s" + "Pages: %d", title, author, pages);
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement