i need help with some code modification
This is a book class
Code:
// The fields.
private String author;
private String title;
private int pages;
private String refNumber;
private int borrowed;
constructors and some methods omitted
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,
:confused:
and this runs in a normal jdk environment but we use an interface called blue j to view things(as a terminal window)
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 {
// 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;
}
}
[ArchAngel added CODE tags]
10-30-2003, 07:28 PM
ArchAngel
What problem are you having? How do you think it should be done?
11-02-2003, 09:54 PM
popirate
You aren't by any chance using the book Fundamentals of Java by Martin Osborne, are you?