ASSIGNMENT 1 ICT167 .docx - ODILIA WU 34061657 import java.util.Iterator import java.util.List public class Change private private private private

ASSIGNMENT 1 ICT167 .docx - ODILIA WU 34061657 import...

This preview shows page 1 - 3 out of 7 pages.

ODILIA WU 34061657 import java.util.Iterator; import java.util.List; public class Change { private List<Integer> coins; private List<String> names; private int largestIdx; private int smallestIdx; public Change(List<Integer> coins, List<String> names) { this.coins = coins; this.names = names; this.mergeName(); this.largestIdx = 0; this.smallestIdx = 0; } private void mergeName() { for (int i = 0; i < names.size(); i++) { for (int j = i + 1; j < names.size(); j++) { if (names.get(i).equals(names.get(j))) { coins.set(i, coins.get(i) + coins.get(j)); if (coins.get(i) > coins.get(largestIdx)) { largestIdx = i; } if (coins.get(i) < coins.get(smallestIdx)) { smallestIdx = i; } names.remove(j); coins.remove(j); } } } } public void information(String customerName) { int idx = Integer.MIN_VALUE; for (int i = 0; i < names.size(); i++) { if (names.get(i).equals(customerName)) { idx = i; break; } } if (idx < 0) { System.out.println("Not found"); } else { System.out.println("Customer : "); System.out.println(customerName + " " + coins.get(idx) + " cents"); System.out.println("Change : "); this.change(coins.get(idx)); }
Image of page 1
} private void change(int coin) { int fifty = 0; int twenty = 0; int ten = 0; int five = 0;
Image of page 2
Image of page 3

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture