import java.io.*;
import java.util.StringTokenizer;
import java.util.Scanner;
public class Machinelist
{
Scanner inFile;
StringTokenizer tokenizer;
String item_selector, product_id,typeOf_machine, file = "machines.dat", select_machine;
int numberOf_machines, quarters, nickels, dimes, num_items, quantity;
machine[] model = new int[numberOf_machines];
public void machinelist()
{
try
{
inFile = new Scanner(new File(file));
//read in from the file
while (inFile.hasNext())
{
typeOf_machine = inFile.next(); //grab first item from "machines.dat " which is the machine type
numberOf_machines = inFile.nextInt(); //grab next item which is number of machines
for(int i = 0; i<=numberOf_machines; i++) //set up loop to read in items the machines share from "machines.dat"
{
quarters = inFile.nextInt();
dimes = inFile.nextInt();
nickels = inFile.nextInt();
num_items = inFile.nextInt();
for (int j = 0; j < num_items; j++) //set up loop to grab the rest of the information from "machines.dat"
{
item_selector = inFile.next();
product_id = inFile.next();
quantity = inFile.nextInt();
}
//create machine objects
machine[numberOf_machines] = new typeOf_machine + i (quarters, nickels dimes, num_items, item_selector,
product_id, quantity);
}
}
//handle exceptions dealing with inputting from file.
catch (FileNotFoundException exception)
{
System.out.println ("The file " + file + " was not found.");
}
catch (IOException exception)
{
System.out.println (exception);
}
//set up main menu to load in
System.out.println("Initializing machines. Please wait...");
System.out.println("Machines are ready.");
System.out.println("Available machines: 100A1, 100A2, 100B1, 100B2, 100B3, 100C1, 100D1");
System.out.println("");
System.out.print("Please select a machine: ");
select_machine = scan.next();
//The way this is set up needs to be changed.
switch (select_machine)
{
case 100A1:
machine[0] = new 100A1 (quarters, nickels dimes, num_items, item_selector,
product_id, quantity);
break;
case 100A1:
machine[1] = new 100A2 (quarters, nickels dimes, num_items, item_selector,
product_id, quantity);
break;
case 100B1:
machine[2] = new 100B1 (quarters, nickels dimes, num_items, item_selector,
product_id, quantity);
break;
case 100B2:
machine[3] = new 100B2 (quarters, nickels dimes, num_items, item_selector,
product_id, quantity);
break;
case 100B3:
machine[4] = new 100B3 (quarters, nickels dimes, num_items, item_selector,
product_id, quantity);
break;
case 100C1:
machine[5] = new 100C (quarters, nickels dimes, num_items, item_selector,
product_id, quantity);
break;
case 100D1:
machine[6] = new 100D (quarters, nickels dimes, num_items, item_selector,
product_id, quantity);
break;
// case secret:
// print out report for machines.
// break;
}
}