|
Page 1 of 1 |
|
Posted: Tue, 12th Jun 2007 13:04 Post subject: need java help, so confused |
|
 |
Hey, I was wondering if someone can help me get started on this java programming exercise
1. Define a class Book.
This class has three private fields: int callNumber, Reader borrower, and Date
dateBorrowed. (Reader is class to be defined later). If a book is in library, field
borrower and dateBorrowed are null. The constructor initializes only the field
callNumber.
Define four methods in this class:
method getBorrower that returns the borrower. This method can also be used to check
the status of a book: If it is in library, the value returned from this method is null.
method processBorrow. This method accepts two parameters: Reader r and Date aDay.
If this book is not in library, output a message. Otherwise, use the parameters to set
fields borrower and dateBorrowed.
method processReturn. This method process a book returned from a reader. It accepts a
parameter that is the date the book is returned. This method calculates the number of
days the book has been borrowed, resets fields borrower and dateBorrowed, and returns
the number of days the book has been borrowed.
method toString. This method return a string "Book " + callNumber.
For this part of the exercise, I was given class Date. How would I get started on creating this class, I am lost at the moment. Thanks
|
|
Back to top |
|
 |
Rinze
Site Admin
Posts: 2343
|
Posted: Tue, 12th Jun 2007 21:54 Post subject: |
|
 |
How can you be lost? It says exactly what you need to do...
Could you say exactly what you don't understand?
|
|
Back to top |
|
 |
|
Posted: Tue, 12th Jun 2007 23:11 Post subject: |
|
 |
i am not that good in java as you can c, lol, i just want to know, how would generate code to determine if is in or not in the library
|
|
Back to top |
|
 |
Rinze
Site Admin
Posts: 2343
|
Posted: Wed, 13th Jun 2007 20:11 Post subject: |
|
 |
Code: | import java.util.Date;
public class Book
{
int callNumber;
Reader borrower;
Date dateBorrowed;
public Book(int callNumber)
{
this.callNumber = callNumber;
}
public Reader getBorrower()
{
return borrower;
}
public void processBorrow(Reader r, Date aDay)
{
if(getBorrower() == null) {
borrower = r;
dateBorrowed = aDay;
}
else {
System.out.println("Book is not here");
}
}
public int processReturn(Date dateReturned)
{
return (int) (dateReturned.getTime() - dateBorrowed.getTime())/(24*60*60*1000);
}
public String toString()
{
return "Book " + callNumber;
}
} |
|
|
Back to top |
|
 |
|
Posted: Sat, 6th Oct 2007 17:29 Post subject: |
|
 |
Nfoce, where Admins do your homework for you!
|
|
Back to top |
|
 |
[sYn]
[Moderator] Elitist
Posts: 8374
|
|
Back to top |
|
 |
Epsilon
Dr. Strangelove
Posts: 9240
Location: War Room
|
Posted: Sun, 7th Oct 2007 23:44 Post subject: |
|
 |
We should have a rule that says "If you don't have over x amount of posts, then you can't get advice or help if it takes more than 30 seconds to answer you"
|
|
Back to top |
|
 |
|
Posted: Fri, 19th Oct 2007 03:22 Post subject: |
|
 |
Epsilon wrote: | We should have a rule that says "If you don't have over x amount of posts, then you can't get advice or help if it takes more than 30 seconds to answer you" |
lets make x=10,000
|
|
Back to top |
|
 |
Page 1 of 1 |
All times are GMT + 1 Hour |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB 2.0.8 © 2001, 2002 phpBB Group
|
|
 |
|