Connecting Tech Pros Worldwide Forums | Help | Site Map

Console Application

Newbie
 
Join Date: May 2007
Posts: 2
#1: May 7 '07
Hi all;

I have this problem so can you help me please ??
Ice cream man makes only two flavors (butter-pecan and tutti-frutti) for the customers who are usually kids. He has one worker who serves both flavors. After each 100 servings, Ice Cream Man calculates number of servings of each flavor to know customers’ trend.

Design a console application to manipulate and display above information. Output should be like the followings and application should run in an infinite loop:

After 100 servings:
55 times butter-pecan and 45 times tutti-frutti.

After 100 servings:
35 times butter-pecan and 65 times tutti-frutti.

I tryed and created this class but it did't run so can you check it for me please


public class IceCreamMania {
public static void main(String[] args) {
IceCream k = new IceCream();

Worker w = new Worker(k);
IceCreamMan I = new IceCreamMan(k);

w.start();
I.start();
}
}

class IceCreamMan extends Thread {
private IceCream icecream;
String butterpecan ;
String tuttifrutti;
private int i=1;
private int j=1;
private IceCreamMania c;

public int getNumber()
{ return(i++); }

public IceCreamMan(IceCream icecream){
this.icecream = icecream;
}

public void run(){
try{
icecream.IceCreamManFood();
//IceCream k= new IceCream();
/*
int i;
int j = 0;


for (i = 0; i < 2000; i++) {
for (j = 0; j < 2000; j++) {
if (i+j ==100) {
System.out.println("butter = " + i);
System.out.println("Totti = " + j);
}
else{
i++;

}}}*/

int i=0;
int j=0;
for(i=0;i<10;i++)
for (j = 0; j < 20; j++)
System.out.println( "butterpecan");

} catch(InterruptedException ie){
System.err.println(ie.getMessage());
}
}
}

class Worker extends Thread {
private IceCream icecream;

public Worker(IceCream kitchen){
this.icecream = kitchen;
}

public void run(){


try{
icecream.WorkerFood();
} catch(InterruptedException ie){
System.err.println(ie.getMessage());
}
}
}


class IceCream {
boolean prep = false;
String sale = null;



synchronized public void WorkerFood()throws InterruptedException {
if(prep == true){
wait();
}

//sale = "SDA";
prep = true;
System.err.println("Yamyam, ice is ready.");
notifyAll();
}

synchronized public void IceCreamManFood() throws InterruptedException{



if(prep == false){
wait();
}
System.err.println("Food, " + sale + " has been eaten.");
sale = null;
prep = false;
}

}

Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#2: May 8 '07

re: Console Application


Quote:

Originally Posted by Maryam1

Hi all;

I have this problem so can you help me please ??
Ice cream man makes only two flavors (butter-pecan and tutti-frutti) for the customers who are usually kids. He has one worker who serves both flavors. After each 100 servings, Ice Cream Man calculates number of servings of each flavor to know customers’ trend.

Design a console application to manipulate and display above information. Output should be like the followings and application should run in an infinite loop:

After 100 servings:
55 times butter-pecan and 45 times tutti-frutti.

After 100 servings:
35 times butter-pecan and 65 times tutti-frutti.

I tryed and created this class but it did't run so can you check it for me please


public class IceCreamMania {
public static void main(String[] args) {
IceCream k = new IceCream();

Worker w = new Worker(k);
IceCreamMan I = new IceCreamMan(k);

w.start();
I.start();
}
}

class IceCreamMan extends Thread {
private IceCream icecream;
String butterpecan ;
String tuttifrutti;
private int i=1;
private int j=1;
private IceCreamMania c;

public int getNumber()
{ return(i++); }

public IceCreamMan(IceCream icecream){
this.icecream = icecream;
}

public void run(){
try{
icecream.IceCreamManFood();
//IceCream k= new IceCream();
/*
int i;
int j = 0;


for (i = 0; i < 2000; i++) {
for (j = 0; j < 2000; j++) {
if (i+j ==100) {
System.out.println("butter = " + i);
System.out.println("Totti = " + j);
}
else{
i++;

}}}*/

int i=0;
int j=0;
for(i=0;i<10;i++)
for (j = 0; j < 20; j++)
System.out.println( "butterpecan");

} catch(InterruptedException ie){
System.err.println(ie.getMessage());
}
}
}

class Worker extends Thread {
private IceCream icecream;

public Worker(IceCream kitchen){
this.icecream = kitchen;
}

public void run(){


try{
icecream.WorkerFood();
} catch(InterruptedException ie){
System.err.println(ie.getMessage());
}
}
}


class IceCream {
boolean prep = false;
String sale = null;



synchronized public void WorkerFood()throws InterruptedException {
if(prep == true){
wait();
}

//sale = "SDA";
prep = true;
System.err.println("Yamyam, ice is ready.");
notifyAll();
}

synchronized public void IceCreamManFood() throws InterruptedException{



if(prep == false){
wait();
}
System.err.println("Food, " + sale + " has been eaten.");
sale = null;
prep = false;
}

}

1.) Please use code tags next time you post code.
2.) Can you describe the errors/exceptions you got when you tried to compile/run it?
Newbie
 
Join Date: May 2007
Posts: 2
#3: May 8 '07

re: Console Application


Hi all;
when I run this code it dos't display what in the problem exactly so can you make some change to run like what in the prblem please???
Reply