CODE
/*
* OrderHistory.java
*
* Created on August 15, 2007, 4:35 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/**
*
* @author Carlton Brown
*/
import java.io.*;
public class OrderHistory {
//interger of the array the constructor of OrderHistory will
//take an array of integers representing the scenario of steps
//in the coffeeVending Project.
public final static int SEL_LARGE_COFFEE=1;
public final static int SEL_SUGAR=2;
public final static int SEL_XSUGAR=3;
public final static int SEL_CREAMER=4;
public final static int SEL_XCREAMER=5;
public final static int SEL_SMALL_COFFEE=6;
public final static int SEL_DONE =-1;
private static int[] scenario1={SEL_LARGE_COFFEE,SEL_SMALL_COFFEE,SEL_SUGAR,SEL_XSUGAR,
SEL_CREAMER,SEL_XCREAMER,SEL_DONE};
//create an array to put output from customer's selection
private int[] readOrder;
/** Creates a new instance of OrderHistory */
public OrderHistory(int [] steps) {
try{
System.out.println("Entering try statement for output");
FileOutputStream fsout = new //Opens file for data
FileOutputStream("newOrders.dat");
ObjectOutputStream out = new ObjectOutputStream(fsout);
out.writeObject(steps);
out.close();
}
catch(FileNotFoundException ex)
{
System.out.println(ex.getMessage());
}
catch(IOException ex)
{
System.out.println(ex.getMessage());
}
try{
System.out.println("Entering try Statement for input");
FileInputStream fsin = new
FileInputStream("newOrder.dat");
ObjectInputStream in = new ObjectInputStream(fsin);
readOrder = (int[])in.readObject();
in.close();
}
catch(FileNotFoundException ex)
{
System.out.println(ex.getMessage());
}
catch(IOException ex)
{
System.out.println(ex.getMessage());
}
}
public int[] getReadOrder() //returns the read order array
{
return readOrder;
}
public static void main(String[] args)
{
OrderHistory myOrderHistory = new
OrderHistory(scenario1);
int[] readOrderBack =myOrderHistory.getReadOrder();
for(int i=0;i<scenario1.length;i++){
int aStep=scenario1[i];
switch(aStep){
case SEL_LARGE_COFFEE:
if(readOrder[i]==OrderHistory[1]){
if(ScenarioSteps.SEL_LARGE_COFFEE)
System.out.println("Found Large Coffee!!!");
else
System.out.println("Large Coffee Not Found");
break;
}
case SEL_SMALL_COFFEE:
if(readOrderBack[i]==OrderHistory[6]){
if(ScenarioSteps.SEL_SMALL_COFFEE)
System.out.println("Found Small Coffee!!!");
else
System.out.println("Small Coffee Not Found");
break;
}
case SEL_SUGAR:
if(readOrderBack[i]==OrderHistory[2]){
if(ScenarioSteps.SEL_SUGAR)
System.out.println("Found Sugar");
else
System.out.println("Sugar not found");
break;
}
case SEL_XSUGAR:
if(readOrderBack[i]==OrderHistory[3]){
if(ScenarioSteps.SEL_XSUGAR)
System.out.println("Found extra sugar");
else
System.out.println("extra sugar not found");
break;
}
case SEL_CREAMER:
if(readOrderBack[i]==OrderHistory[4]){
if(ScenarioSteps.SEL_CREAMER)
System.out.println("Found creamer");
else
System.out.println("Creamer not found");
break;
}
case SEL_XCREAMER:
if(readOrderBack[i]==OrderHistory[5]){
if(ScenarioSteps.SEL_XCREAMER)
System.out.println("Found extra creamer");
else
System.out.println("Extra creamer not found");
break;
}
case SEL_DONE:
if(readOrderBack[i]==OrderHistory[-1]){
if(ScenarioSteps.SEL_DONE)
System.out.println("Found done");
else
System.out.println("Done not found");
break;
}
}
}
}