Name (please type legibly, ideally in block letters): ______________________________________________________________________
1. Write down a piece of code that, given two arrays amount and unitCost of the same size, returns the overall cost of the purchase, i.e., the value cost = amount[0]*unitCost[0] + amount[1]*unitCost[1] + ...
Solution: cost = 0; for (int i = 0; i < amount.length; i++) c += amount[i] * unitCost[i];2. Write down a method expensive that, given an array unitCost, returns the number of the items whose unit cost is above 10 dollars.
Solution:
public static int expensive (double[] unitCost){
int number = 0;
for (int i = 0; i < unitCost.length; i++)
if (unitCost[i] > 10.0) number++;
return number;
}