import java.util.Scanner; import java.io.File; import java.io.FileNotFoundException; import java.util.Arrays; class Change { /* * for easier printing */ public static void p(Object o) {System.out.print(o);} public static void pl(Object o) {System.out.println(o);} /* * main method */ public static void main( String[] args ) { // You should use the code below and the examples // miss_example // knap_example // You'll want to // // (1) read in the file name // (2) read in the change file data // first, the number of denominations // then, the denominations themselves // (3) ask for an amount to make change for // (4) then, compute the minimum solution // print the minimum number of coins // and print the coins used Scanner kbd = new Scanner(System.in); p( "Enter a filename such as coins1.txt: " ); String filename = kbd.nextLine(); filename = filename.trim(); pl("Now trying to open " + filename); Scanner file = null; try { // in case the file's not there file = new Scanner(new File(filename)); } catch (FileNotFoundException e) { pl("File " + filename + " not found."); pl( e ); } // get integer at the start of the file: int num_coins = file.nextInt(); pl("Read the # of coins = " + num_coins); // create an array, coins, to hold the coins: int[] coins = new int[num_coins]; // here, you'll need to loop in order to read each coin in... // It's useful for debugging to be able to print an array pl("The array, coins, is " + Arrays.toString( coins )); // // here's the DP - all in main is OK or, if you prefer, in another function // pl("Input the value to make change for: "); int amt = kbd.nextInt(); // this will crash if it's not an int - that's OK. pl("Solution:"); pl("I don't know -- yet!"); } }