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
def getTotalItemFees = { | |
( for (item <- items) yield item._1.getFee * item._2 ).sum | |
} | |
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
def getTotalItemFees = { | |
val fees = | |
for (item <- items) | |
yield item._1.getFee() * item._2 | |
fees.sum // High order function on the list that came out of the for loop | |
} |
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
private val items = new HashMap[CartItem, Int] | |
def getTotalItemFees : Double = { | |
var sum = 0.0 | |
for (item <- items) | |
sum += (item._1.getFee() * item._2) | |
sum | |
} |
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
private Map<CartItem, Integer> cart = new HashMap<CartItem, Integer>(); | |
public Double getTotalItemFees() { | |
Double fees = 0.0; | |
for (Map.Entry<CartItem, Integer> entry : cart.entrySet()) { | |
Integer quantity = entry.getValue(); | |
CartItem cartItem = entry.getKey(); | |
fees += (quantity * cartItem.getFee()) | |
} | |
return fees; |
NewerOlder