i need help with some code modification
This is a book class
constructors and some methods omittedCode:// The fields. private String author; private String title; private int pages; private String refNumber; private int borrowed;
basically the integer field borrowed is meant to keep a count of the number of times has been borrowed, what i need help with is adding a mutator borrow, and this should update the field by 1 each time it is called, include an accessor getBorrowed, that returns a value of this new field as its result.
The main code is below it self, if anyone has time to look at it please help,
![]()
and this runs in a normal jdk environment but we use an interface called blue j to view things(as a terminal window)
[ArchAngel added CODE tags]Code:/** * @author (Aisha Aliyu) * @version (28/10/2003) */ class Book { // 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, String ref, int borrow) { author = bookAuthor; title = bookTitle; pages = bookPages; refNumber = ref; borrowed = borrow; } // The number of pages. public int getPages() { return pages; } // return the refrence number of the book public String getRefNumber() { return refNumber; } // Simulate the printing of the author's name. public void printAuthor() { System.out.println("*Book Author*= " + author); } // Simulate the printing of the book's title. public void printTitle() { System.out.println("*Book Title* = " + title); } // Simulate the printing of the book details. public void printDetails() { if(refNumber == "") { System.out.println("*Book Author* = " + author); System.out.println("*Book Title* = " + title); System.out.println("*Pages* = " + pages); System.out.println("*Reference Number* = " + refNumber); } else { System.out.println("*Reference Number* = zzz"); } } // The refrence mutator. public void setRefNumber(String ref) { if(ref.length() < 3) { System.out.println("The reference number must be at least 3 characters"); } else { refNumber = ref; } } // The Borrowed mutator. public int borrowed() { return borrowed; } }


Reply With Quote


Bookmarks