This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public String statement() | |
{ | |
double totalAmount = 0; | |
int frequentRenterPoints = 0; | |
Enumeration<Rental> allRentals = rentals.elements(); | |
String result = "Rental record for " + getName() + "\n"; | |
while (allRentals.hasMoreElements()) | |
{ | |
Rental each = (Rental) allRentals.nextElement(); | |
frequentRenterPoints += each.getFrequentRenterPoints(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public String statement() | |
{ | |
int frequentRenterPoints = 0; | |
Enumeration<Rental> allRentals = rentals.elements(); | |
String result = "Rental record for " + getName() + "\n"; | |
while (allRentals.hasMoreElements()) | |
{ | |
Rental each = (Rental) allRentals.nextElement(); | |
frequentRenterPoints += each.getFrequentRenterPoints(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package bowling | |
class Frame | |
{ | |
public Frame(){} | |
public Frame(Frame nextFrame) | |
{ | |
this.nextFrame = nextFrame | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int calculateAveragePreviousPercentageComplete() { return reduceAndAverageActivitiesBy(PREVIOUS_PERCENTAGE_COMPLETE); } | |
int calculateAverageCurrentPercentageComplete() { return reduceAndAverageActivitiesBy(CURRENT_PERCENTAGE_COMPLETE); } | |
int calculateAverageProgressPercentage() { return reduceAndAverageActivitiesBy(PROGRESS_PERCENTAGE); } | |
int reduceAndAverageActivitiesBy( Functor2<Integer, StudentActivityByAlbum, Integer> functor){ | |
return fold(0, activities, functor) / activities.size(); } | |
static final Functor2<Integer, StudentActivityByAlbum, Integer> PREVIOUS_PERCENTAGE_COMPLETE = | |
new Functor2<Integer, StudentActivityByAlbum, Integer>(){ | |
@Override public Integer execute(Integer accumulator, StudentActivityByAlbum value) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int calculateAveragePreviousPercentageComplete() { return sumAndAverageTheValueOfField(PREVIOUS_PERCENTAGE_COMPLETE); } | |
int calculateAverageCurrentPercentageComplete() { return sumAndAverageTheValueOfField(CURRENT_PERCENTAGE_COMPLETE); } | |
int calculateAverageProgressPercentage() { return sumAndAverageTheValueOfField(PROGRESS_PERCENTAGE); } | |
int sumAndAverageTheValueOfField( Functor<StudentActivityByAlbum, Integer> fieldGetter){ | |
return addAll(collect( activities, fieldGetter)) / activities.size(); } | |
<T> int addAll(Iterable<Integer> items){ return reduce( items, PLUS); } | |
static final Functor<StudentActivityByAlbum, Integer> PREVIOUS_PERCENTAGE_COMPLETE = new Functor<StudentActivityByAlbum, Integer>(){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package bowling | |
class Frame | |
{ | |
public add(roll) { rolls << roll } | |
public addBonus(roll) { rolls << roll } | |
public score(){ rolls.sum() } | |
private rolls = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package bowling | |
class Frame | |
{ | |
public add(roll) { rolls << roll } | |
public addBonus(roll) { bonusRolls << roll } | |
public score() | |
{ | |
if(isStrike() || isSpare()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BusinessObject { | |
public void actionMethod() { | |
// Other things | |
Service myServiceObject = Service.getInstance(); | |
myServiceObject.doService(); | |
// Other things | |
} | |
} | |
class Service { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BusinessObject { | |
public void actionMethod() { | |
// Other things | |
//No Change! | |
Servicec myServiceObject = Service.getInstance(); | |
myServiceObject.doService(); | |
// Other things | |
} | |
} |
OlderNewer