Grading rules:
The maximum number of points is 15, but the quiz is counted out of 10 since it
was so rushed.
1 pt for declaring the class properly
3 pts for the correct declarations of data members (should be private)
2 pts for the constructor
1 pt each for getTitle(). getUserID() and numberOfCheckouts()
2 pts each for checkIn(), checkOut(), and isCheckedOut().
Solution:
public class LibraryBook{
private String title;
private int timesCheckedOut;
private int currentUsersID;
public LibraryBook(String _title){
title = _title;
timesCheckedOut = 0;
currentUsersID = 0;
}
public String getTitle() {
return title;
}
public int getUserID() {
return currentUsersID;
}
public int numberOfCheckOuts() {
return timesCheckedOut;
}
public void checkOut(int userID) {
timesCheckedOut++;
currentUsersID = userID;
}
public void checkIn() {
currentUsersID = 0;
}
public boolean isCheckedOut() {
return currentUsersID != 0;
}
}
Last updated 3-5-2008