//ClockDriver.java //uncomment the commented sections to test your modified Clock.java //do not make any other changes. Do not submit this file. import javax.swing.*; public class ClockDriver { public static void main(String[] args) { String command; //array of 100 Clock objects. //no Clock objects created here, just the array elements (which are reference variables) //array elements automatically initialized to null. Clock [] theClocks = new Clock[100]; int hour, minute, second; do { command = JOptionPane.showInputDialog("Enter command: \n" + " Clock3\n ClockCopy\n ClockString\n equals\n increment\n toString\n quit"); if (command.equalsIgnoreCase("Clock3")) { //3-values constructor hour = Integer.parseInt(JOptionPane.showInputDialog("Enter hour")); minute = Integer.parseInt(JOptionPane.showInputDialog("Enter minute")); second = Integer.parseInt(JOptionPane.showInputDialog("Enter second")); System.out.println("Constructor invoked with " + hour + ":" + minute + ":" + second); theClocks[getIndex()] = new Clock(hour,minute,second); } /* else if (command.equalsIgnoreCase("ClockString")) { //**** HMK string constructor String stringTime = JOptionPane.showInputDialog("Enter time as hh:mm:ss"); System.out.println("Constructor invoked with " + stringTime); theClocks[getIndex()] = new Clock(stringTime); } else if (command.equalsIgnoreCase("ClockCopy")) { //**** HMK copy constructor int fromIndex = Integer.parseInt(JOptionPane.showInputDialog("Enter index of object to copy from")); System.out.println("copy Constructor invoked with " + theClocks[fromIndex]); theClocks[getIndex()] = new Clock(theClocks[fromIndex]); } */ /* else if (command.equalsIgnoreCase("increment")) { //**** HMK increment time int seconds = Integer.parseInt(JOptionPane.showInputDialog("Enter number of seconds to increment by")); int i = getIndex(); theClocks[i].increment(seconds); } */ else if (command.equalsIgnoreCase("equals")) { int objIndex = Integer.parseInt(JOptionPane.showInputDialog("Enter index of clock object")); int argIndex = Integer.parseInt(JOptionPane.showInputDialog("Enter index of argument clock object")); if (theClocks[objIndex].equals(theClocks[argIndex])) System.out.println("objects are equal"); else System.out.println("objects are not equal"); } else if (command.equalsIgnoreCase("toString")) { System.out.println("toString invoked: " + theClocks[getIndex()]); } } while(!command.equalsIgnoreCase("quit")); } //***input int from user for array index. //could add some checking to ensure index is valid...to avoid subsequent crash public static int getIndex() { return Integer.parseInt(JOptionPane.showInputDialog("Enter index of object to access")); } }