@Test(expected = IllegalArgumentException.class) public void shouldNotAcceptEmptyArrayOfMoneys() { returnChange.calculate(new int[0], 7); }
public List<Integer> calculate(int[] moneys, int billAmount) { validateInputData(moneys, billAmount); List<Integer> change = new LinkedList<Integer>(); while (billAmount > 0 && moneys.length > 0) { for (int i = moneys.length - 1; i >= 0; i--) { if (billAmount - moneys[i] >= 0) { change.add(moneys[i]); billAmount -= moneys[i]; break; } } } return change; }
ReturnChange { public List<Integer> calculate(int[] moneys, int billAmount) { validateInputData(moneys, billAmount); List<Integer> change = new LinkedList<Integer>(); while (billAmount > 0 && moneys.length > 0) { for (int i = moneys.length - 1; i >= 0; i--) { if (billAmount - moneys[i] >= 0) { change.add(moneys[i]); billAmount -= moneys[i]; break; } } } return change; } }
ReturnChange { public List<Integer> calculate(int[] moneys, int billAmount) { validateInputData(moneys, billAmount); List<Integer> change = new LinkedList<Integer>(); while (billAmount > 0 && moneys.length > 0) { for (int i = moneys.length - 1; i >= 0; i--) { if (billAmount - moneys[i] >= 0) { change.add(moneys[i]); billAmount -= moneys[i]; break; } } } return change; }  }
ReturnChange { public List<Integer> calculate(int[] moneys, int billAmount) { validateInputData(moneys, billAmount); List<Integer> change = new LinkedList<Integer>(); while (billAmount > 0 && moneys.length > 0) { for (int i = moneys.length - 1; i >= 0; i--) { if (billAmount - moneys[i] >= 0) { change.add(moneys[i]); billAmount -= moneys[i]; break; } } } return change; }  List<Integer> calculate(int[] moneys, int billAmount); }
ReturnChange { public List<Integer> calculate(int[] moneys, int billAmount) { validateInputData(moneys, billAmount); List<Integer> change = new LinkedList<Integer>(); while (billAmount > 0 && moneys.length > 0) { for (int i = moneys.length - 1; i >= 0; i--) { if (billAmount - moneys[i] >= 0) { change.add(moneys[i]); billAmount -= moneys[i]; break; } } } return change; }  List<Integer> calculate(int[] moneys, int billAmount);  }