Hi,

I have created a java application and need to display the output it in an
applet - is there an easy way to do this? (or any suggestions would be
appreciated) I have included the main class file below:

Thanks in advance,

Tom.


public class Personi
{
static int numberOfSandwichesEaten;
static int wallet = 400;

public static void main(String[] args)
{
Personi sandwichMan = new Personi();
SandwichMachine theMachine = new SandwichMachine();
SandwichMachine.setPrices(120,140);
SandwichMachine.setCreditLimit(wallet);
sandwichMan.makeInitialSandwiches(theMachine);
numberOfSandwichesEaten = sandwichMan.checkForSale(theMachine);
// The prices have been set and the machine has been filled

showContents(sandwichMan, theMachine);

Personi hungryStudent = new Personi();
printThis ("\nA student has just walked up to the machine......");
printThis ("He wants a cheese sandwich and has the correct change (140
pence)");
pauseForAShortMoment();
hungryStudent.buySandwich("cheese", 140, theMachine);
// A new person, hungryStudent has been created and he has purchased a
cheese sandwich (he had the right money)

showContents(sandwichMan, theMachine);

printThis ("\nThe sandwich was nice, but it didn't satisfy the hungry
student......");
printThis ("He wants another cheese sandwich, but, this time only puts
in 135 pence");
pauseForAShortMoment();
hungryStudent.buySandwich("cheese", 135, theMachine);
// The student has just put in too little money for the sandwich, the
error is displayed, and the money returned.

showContents(sandwichMan, theMachine);

printThis ("\nThe student then remembers he needs to buy 3 egg
sandwiches for his friends,");
printThis ("as well as the one cheese sandwich that he wanted");
printThis ("He puts in 3 lots of 120 pence and selects Egg for his
friends' sandwiches");
printThis ("and 140 pence for his cheese sandwich.....");
pauseForAShortMoment();
hungryStudent.buySandwich("egg", 120, theMachine);
pauseForAShortMoment();
hungryStudent.buySandwich("egg", 120, theMachine);
pauseForAShortMoment();
hungryStudent.buySandwich("egg", 120, theMachine);
pauseForAShortMoment();
hungryStudent.buySandwich("cheese", 140, theMachine);
// 3 egg sandwiches are bought, and one cheese exact money given, no
change needed

showContents(sandwichMan, theMachine);

printThis ("\nThat Student must have a serious eating disorder......");
printThis ("He wants another egg sandwich for himself, and puts in a two
pound coin");
pauseForAShortMoment();
hungryStudent.buySandwich("egg", 200, theMachine);
// The student has just put in too much money for the egg sandwich, so
his change is returned.

showContents(sandwichMan, theMachine);

printThis ("\nWho'd believe it, the greedy student is back for another
egg......");
printThis ("He puts in the correct change, but .... there's no egg left
in the machine ....");
pauseForAShortMoment();
hungryStudent.buySandwich("egg", 120, theMachine);

showContents(sandwichMan, theMachine);

}

public void makeInitialSandwiches(SandwichMachine machine)
{
machine.fillMachine();
}

public static void printThis(String output)
{
System.out.println(output);
}
// this method produces all output for the program

public static int showNumberOfCheese(SandwichMachine machine)
{
return machine.checkCheeseLeft();
}

public static int showNumberOfEgg(SandwichMachine machine)
{
return machine.checkEggLeft();
}

public static int showMoneyLeft(SandwichMachine machine)
{
return machine.checkMoneyLeft();
}

public static int checkForSale(SandwichMachine machine)
{
return machine.howManyBought();
}

public static void buySandwich (String flavour, int money, SandwichMachine
machine)
{
machine.dispenseSandwich (flavour, money);
}

public static void showContents(Personi tempBloke, SandwichMachine
tempMachine)
{
tempBloke.printThis("\nLets check the machine, what is in it at the
moment?....");
tempBloke.printThis(showNumberOfCheese(tempMachine)+ " Cheese Sandwiches
left in the Machine");
tempBloke.printThis(showNumberOfEgg(tempMachine)+ " Egg Sandwiches left
in the Machine");
tempBloke.printThis("Therefore, the total number of sandwiches in the
machine is " + (showNumberOfCheese(tempMachine) +
showNumberOfEgg(tempMachine) + " sandwiches"));
tempBloke.printThis("and .....");
tempBloke.printThis("There is "+ showMoneyLeft(tempMachine) + " Pence
left in the Machine");
numberOfSandwichesEaten = checkForSale(tempMachine);
tempBloke.printThis(numberOfSandwichesEaten + " Sandwiches have been
eaten since it was last filled");
}

}// end of class