Skip to content

Instantly share code, notes, and snippets.

@philipschwarz
Created July 2, 2011 09:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philipschwarz/1059899 to your computer and use it in GitHub Desktop.
Save philipschwarz/1059899 to your computer and use it in GitHub Desktop.
After applying "Replace Temp with Query" to frequentRenterPoints
public String statement()
{
Enumeration<Rental> allRentals = rentals.elements();
String result = "Rental record for " + getName() + "\n";
while (allRentals.hasMoreElements())
{
Rental each = (Rental) allRentals.nextElement();
// show figures for this rental
result += "\t" + each.getMovie().getTitle() + "\t" + String.valueOf(each.getCharge()) + "\n";
}
// add footer lines
result += "Amount owed is " + String.valueOf(getTotalCharge()) + "\n";
result += "You earned " + getTotalFrequentRenterPoints() + " frequent renter points";
return result;
}
private double getTotalCharge()
{
double result = 0;
for(Rental rental : rentals)
{
result += rental.getCharge();
}
return result;
}
private double getTotalFrequentRenterPoints()
{
double result = 0;
for(Rental rental : rentals)
{
result += rental.getFrequentRenterPoints();
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment