Final
Takehome Exam
Handed out: Friday, May 9
Due: 11 am, Friday, May 16
Do all 7 problems. You have 7 days to do this exam. There are 100 possible points.
Notes
Problems
public int cost() {
int total = 0;
for(int i = 0; i < purchases.size(); i++) {
Purchase p = (Purchase) purchases.get(i);
total += p.item().cost() + p.shipping().cost();
}
return total;
}
Also, suppose the Cart’s maxDays() method is implemented as follows:
public int maxDays() {
int max = 0;
for(int i = 0; i < purchases.size(); i++) {
Purchase p = (Purchase) purchases.get(i);
max = Math.max(max, p.shipping().days());
}
return max;
}
Refactor this design to make it more elegant. You are welcome to add/remove classes and methods if it is helpful. Briefly explain why your design is more elegant.import java.util.ArrayList;
public class BookLibrary {
private ArrayList myBooks = new ArrayList();
public void rename(String oldName, String newName) {
//loop thru array to find the book to be renamed
Book aBook = null;
for( int i = 0; i < myBooks.size(); i++ ) {
Book tempBook = (Book) myBooks.get(i);
if( tempBook.getName().equals(oldName)) {
aBook = tempBook;
break;
}
}
//rename the book if match was found in array
if(aBook == null) return;
aBook.setName(newName);
}
...other methods and instance variables...
}
class Book
{
private String name;
public String getName() { return name; }
public void setName(String newName) { name = newName; }
...other methods and instance variables...
}
In an actual competition, the user of the program would start up the program and then enter all the information about the events, teams, and players through some GUI. Then, as the competition progressed, the user would use the GUI to enter the data gathered for each event (e.g., the time or distance for each team, any penalties, etc.). When the competition ended, the final scores would be computed from the data and then the scores and rankings of all teams in all events would be displayed.
Design the underlying model and ignore the GUI. Create UML diagrams, including methods and fields, as appropriate. You don't need to implement anything, but implementing parts of it may help you see faults in your design.
The easier it is for me to understand your design, the more points you'll get, so you might want to include some explanations as to why you made particular decisions regarding various parts of the overall design.
Treat me as the customer who is paying you to develop the software and so ask me for any clarifications you need in order to finish your design. As usual, I will share the clarifications with everyone, if appropriate.