Associate
- Joined
- 28 May 2008
- Posts
- 346
Hi i am currently studying for my Year 1 Java exam by going over past papers! I am stuck on one of the questions and was wondering if any of you programming whizzs could give me a hand the question is -
Question 8.
Consider the following classes Date and LibraryBook:
class Date {
private int day, month, year;
public Date(int aDay, int aMonth, int aYear) {
//assigns values to the three properties
}
public Date (Date copyDate) {
//creates a date identical to copyDate
}
public boolean isAfter (Date d) {
//returns true if the date of the object calling the
//method is after d
}
public void addWeeks(int numWeeks){
//adds numWeeks to a date
}
}// Date
class LibraryBook {
private String title, author, code;
private String borrowerName;
//additional properties required
public LibraryBook(String title, String author,
String code) {
//assigns values to corresponding properties
}
public void createLoan(int day, int month, int year,
String name, int numWeeks){
//creates and sets appropriate values for loanDate
//and dueDate and sets values of borrowerName and
//onLoan
}
public boolean isOverdue(Date d) {
//determines whether the book is overdue
}
public boolean isOnLoan(){
//determines whether the book is on loan
}
public String getBorrowerName(){
//returns the name of the borrower
}
}// LibraryBook
(a) Provide the following for the class LibraryBook:
(i) declare additional properties, one to represent whether the library book is on loan, and two instances of the class Date, one for the date on which the loan starts and one for the date on which the book is due to be returned;
(3 marks)
(ii) code for the methods createLoan, isOverdue, isOnLoan and getBorrowerName.
(12 marks)
(b) Write fragments of code which could be included in an application class to:
(i) create an instance of the class LibraryBook (with suitable values);
(2 marks)
(ii) create a loan for this book for 12 weeks for a borrower called Jones (you will need to specify suitable values for the day, month and year);
(2 marks)
(iii) creates an instance of the class Date for today’s date and then checks whether the book is on loan and, if so, whether it is overdue. If it is, the borrower’s name should be printed out.
(6 marks)
(c) Write another version of the method createLoan in the class LibraryBook which replaces the three parameters for the day, month and year with a single parameter which is an instance of the class Date and show how this method could be used to provide an alternative answer to b(ii).
(5 marks)
Any help would be greatly aprecicated
Question 8.
Consider the following classes Date and LibraryBook:
class Date {
private int day, month, year;
public Date(int aDay, int aMonth, int aYear) {
//assigns values to the three properties
}
public Date (Date copyDate) {
//creates a date identical to copyDate
}
public boolean isAfter (Date d) {
//returns true if the date of the object calling the
//method is after d
}
public void addWeeks(int numWeeks){
//adds numWeeks to a date
}
}// Date
class LibraryBook {
private String title, author, code;
private String borrowerName;
//additional properties required
public LibraryBook(String title, String author,
String code) {
//assigns values to corresponding properties
}
public void createLoan(int day, int month, int year,
String name, int numWeeks){
//creates and sets appropriate values for loanDate
//and dueDate and sets values of borrowerName and
//onLoan
}
public boolean isOverdue(Date d) {
//determines whether the book is overdue
}
public boolean isOnLoan(){
//determines whether the book is on loan
}
public String getBorrowerName(){
//returns the name of the borrower
}
}// LibraryBook
(a) Provide the following for the class LibraryBook:
(i) declare additional properties, one to represent whether the library book is on loan, and two instances of the class Date, one for the date on which the loan starts and one for the date on which the book is due to be returned;
(3 marks)
(ii) code for the methods createLoan, isOverdue, isOnLoan and getBorrowerName.
(12 marks)
(b) Write fragments of code which could be included in an application class to:
(i) create an instance of the class LibraryBook (with suitable values);
(2 marks)
(ii) create a loan for this book for 12 weeks for a borrower called Jones (you will need to specify suitable values for the day, month and year);
(2 marks)
(iii) creates an instance of the class Date for today’s date and then checks whether the book is on loan and, if so, whether it is overdue. If it is, the borrower’s name should be printed out.
(6 marks)
(c) Write another version of the method createLoan in the class LibraryBook which replaces the three parameters for the day, month and year with a single parameter which is an instance of the class Date and show how this method could be used to provide an alternative answer to b(ii).
(5 marks)
Any help would be greatly aprecicated