//MonsterDriver.java //do not make any changes. Do not submit this file. import javax.swing.*; public class MonsterDriver { public static void main(String[] args) { String command; //array of 100 Monster objects. //no Monster objects created here, just the array elements (which are reference variables) //array elements automatically initialized to null. Monster [] theMonsters = new Monster[100]; String name; int size, points; do { command = JOptionPane.showInputDialog("Enter command: \n" + " Monster3\n MonsterCopy\n MonsterString\n equals\n increment\n" + " toString\n number \nquit"); if (command.equalsIgnoreCase("Monster3")) { //3-values constructor name = JOptionPane.showInputDialog("Enter name"); size = Integer.parseInt(JOptionPane.showInputDialog("Enter size")); points = Integer.parseInt(JOptionPane.showInputDialog("Enter points")); System.out.println("Constructor invoked with " + name + ":" + size + ":" + points); theMonsters[getIndex()] = new Monster(name,size,points); } else if (command.equalsIgnoreCase("MonsterString")) { // "string" constructor String stringMonster = JOptionPane.showInputDialog("Enter monster as name-size-points"); System.out.println("Constructor invoked with " + stringMonster); theMonsters[getIndex()] = new Monster(stringMonster); } else if (command.equalsIgnoreCase("MonsterCopy")) { // copy constructor int fromIndex = Integer.parseInt(JOptionPane.showInputDialog("Enter index of object to copy from")); System.out.println("copy Constructor invoked with " + theMonsters[fromIndex]); theMonsters[getIndex()] = new Monster(theMonsters[fromIndex]); } else if (command.equalsIgnoreCase("increment")) { // mutate size int growth = Integer.parseInt(JOptionPane.showInputDialog("Enter growth")); int i = getIndex(); theMonsters[i].increment(growth); } else if (command.equalsIgnoreCase("equals")) { int objIndex = Integer.parseInt(JOptionPane.showInputDialog("Enter index of Monster object")); int argIndex = Integer.parseInt(JOptionPane.showInputDialog("Enter index of argument Monster object")); if (theMonsters[objIndex].equals(theMonsters[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: " + theMonsters[getIndex()]); } else if (command.equalsIgnoreCase("number")) { System.out.println("Number of monsters unleashed: " + Monster.getNumberMonsters()); } } 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")); } }