import java.util.*; public class Client { private static Random rand = new Random(); public static void main(String[] args) throws Exception { // List scenario = createRandomScenario(10, 10, 100, 1000, 100000); List scenario = createSimpleScenario(); System.out.println(scenario); double budget = 2000; Set allocations = generateOptions(budget, scenario); printAllocations(allocations); } public static Set generateOptions(double budget, List sites) { Set allocations = new HashSet<>(); return generateOptions(budget, sites, allocations); } private static Set generateOptions(double budget, List sites, Set allocations) { if (sites.isEmpty()) { return allocations; } Region temp = sites.remove(); if (budget >= temp.baseCost) { budget -= temp.baseCost; } } /////////////////////////////////////////////////////////////////////////// // PROVIDED HELPER METHODS - **DO NOT MODIFY ANYTHING BELOW THIS LINE!** // /////////////////////////////////////////////////////////////////////////// public static void printAllocations(Set allocations) { System.out.println("All Allocations:"); for (Allocation a : allocations) { System.out.println(" " + a); } } public static List createRandomScenario(int numLocs, int minPop, int maxPop, double minCostPer, double maxCostPer) { List result = new ArrayList<>(); for (int i = 0; i < numLocs; i++) { int pop = rand.nextInt(minPop, maxPop + 1); double cost = rand.nextDouble(minCostPer, maxCostPer) * pop; result.add(new Region("Region #" + i, pop, round2(cost))); } return result; } public static List createSimpleScenario() { List result = new ArrayList<>(); result.add(new Region("Region #1", 50, 500)); result.add(new Region("Region #2", 100, 700)); result.add(new Region("Region #3", 60, 1000)); result.add(new Region("Region #4", 20, 1000)); result.add(new Region("Region #5", 200, 900)); return result; } private static double round2(double num) { return Math.round(num * 100) / 100.0; } }