This is a take-home lab we have to do. I have all but this last part working. The lab states
"Write these methods:
public void displayBook() displays the book information on the screen like this:
Title : Ghost Stories of British Columbia
Author : Jo-Anne Christensen
ISBB : 0-88882-191-3
Pages : 192
Paperback : yes
Suggested price : $17.99
Note that the display method checks the boolean field and displays “yes” if true, “no” if
false.
public boolean isHeavyBook() returns true if the book is hard-cover (not
paperback) and has at least 500 pages. Use a symbolic constant for the number of
pages." So I think I have the displayBook method right but I am unclear as to how to write the isHeavyBook method which is supposed to update the Paperback field in the displayBook method.
Here is my code so far:
I think I also have something wrong with displayBook info method because if I am checking it it is hardcover in another method how do I get that method to use the isHeavyBook method for checking? I hope whoever reads this can understand what I am trying to say and can help me. Thank you in advance./** * This class shows some of the relevant attributes of a Book * * @author Randy Watson * @version October 5 2013 */ public class Book { public static final int PAGES_AMOUNT = 500; public String title; public String author; public String bookCode; public int numPages; public boolean pBack; public double retailCost; /** * This is the default constructor */ public Book() { title = ""; author = ""; bookCode = ""; numPages = 0; pBack = false; retailCost = 0.0; } /** * Non-default constructor */ public Book(String nameOf, String writer, String iSBN, int pageCount, boolean paperBack, double cost) { title = nameOf; author = writer; bookCode = iSBN; if(pageCount <= 0) System.out.println("Page amount must be positive"); else pageCount = PAGES_AMOUNT; pBack = paperBack; retailCost = cost; } /** * @return The title of the book */ public String getTitle(String bookTitle) { return title; } /** * @return The books author */ public String getAuthor(String bookAuthor) { return author; } /** * @return Book ISBN number */ public String getISBN(String bookNumber) { return bookCode; } /** * @return The number of pages in the book */ public int getNumberOfPages(int pageAmount) { return numPages; } /** * @return if the book is paperback or hardcover */ public boolean getPaperBack(boolean heavyCover) { return pBack; } /** * @return the suggested retail price of the book */ public double getRetailCost(double bookCost) { return retailCost; } /** * Mutator Method to change the book title */ public void setBookTitle(String title1) { title = title1; } /** * Mutator Method to change the book's author */ public void setAuthor(String author1) { author = author1; } /** * Mutator Method to change the book's ISBN number */ public void setISBN(String newISBN) { bookCode = newISBN; } /** * Mutator Method to change the amount of pages in the book */ public void setPages(int newPageAmount) { if (numPages <= 0) numPages = newPageAmount; } /** * Mutator method for checking if the book is hardcover or paperback */ public void setHardCover(boolean heavyBook) { pBack = heavyBook; } /** * Mutator method for changing the cost of the book */ public void setBookCost(double bookCost) { if(retailCost <= 0) System.out.println("Cost must be more than zero"); else retailCost = bookCost; } /** * Method to display the fields of the book class and to check if the book us hardcover or not */ public void displayBook() { System.out.println("Title : " + title); System.out.println("Author : " + author); System.out.println("ISBN : " + bookCode); System.out.println("Pages : " + numPages); System.out.println("Paperback : " + pBack); System.out.println("Suggested price : " + retailCost); } /** * @return Method for determining if book is hardcover or not */ public boolean isHeavyBook() { boolean heavy; if(pBack == true && PAGES_AMOUNT) { return true; } return false; } }