Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * A class that maintains information on a book.
- * This might form part of a larger application such
- * as a library system, for instance.
- *
- * @author (Insert your name here.)
- * @version (Insert today’s date here.)
- */
- import java.util.Scanner;
- public class Book
- {
- Scanner scan = new Scaner(System.in)
- // The fields.
- private String author;
- private String title;
- private int pages;
- private String refNumber;
- private int borrowed;
- /**
- * Set the author and title fields when this object
- * is constructed.
- */
- public Book(String bookAuthor, String bookTitle, int bookPages)
- {
- author = bookAuthor;
- title = bookTitle;
- pages = bookPages;
- refNumber = "";
- borrowed = 0 ;
- }
- public String getAuthor
- {
- return author;
- }
- public String getTitle
- {
- return title;
- }
- public String getRefNumber()
- {
- return refNumber;
- }
- public void printAuthor()
- {
- System.out.println("Author: " + author);
- }
- public void printTitle()
- {
- System.out.println("Title: " + title);
- }
- public int getPages()
- {
- return pages;
- }
- public int getBorrowed()
- {
- return borrowed;
- }
- public void setRefNUmber(String ref)
- {
- if(ref.length() >= 3)
- {
- refNumber = ref;
- }
- else
- {
- System.out.println("Error bro! at least 3 character");
- }
- }
- public void borrow()
- {
- borrowed = borrowed + 1;
- }
- public void printDetails()
- {
- System.out.println("Title: " + title + ", ");
- System.out.println("Author: " + author + ", ");
- System.out.println("Pages: " + pages);
- if (refNUmber.length() != 0)
- {
- System.out.println("Ref. Num :" + refNumber);
- }
- else
- System.out.println("Ref. Num : ZZZ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment