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(Ice Cream icecream){
this.icecream = icecream;
}
public void run(){
try{
icecream.IceCre amManFood();
//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.prin tln("butter = " + i);
System.out.prin tln("Totti = " + j);
}
else{
i++;
}}}*/
int i=0;
int j=0;
for(i=0;i<10;i+ +)
for (j = 0; j < 20; j++)
System.out.prin tln( "butterpeca n");
} catch(Interrupt edException ie){
System.err.prin tln(ie.getMessa ge());
}
}
}
class Worker extends Thread {
private IceCream icecream;
public Worker(IceCream kitchen){
this.icecream = kitchen;
}
public void run(){
try{
icecream.Worker Food();
} catch(Interrupt edException ie){
System.err.prin tln(ie.getMessa ge());
}
}
}
class IceCream {
boolean prep = false;
String sale = null;
synchronized public void WorkerFood()thr ows InterruptedExce ption {
if(prep == true){
wait();
}
//sale = "SDA";
prep = true;
System.err.prin tln("Yamyam, ice is ready.");
notifyAll();
}
synchronized public void IceCreamManFood () throws InterruptedExce ption{
if(prep == false){
wait();
}
System.err.prin tln("Food, " + sale + " has been eaten.");
sale = null;
prep = false;
}
}
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(Ice Cream icecream){
this.icecream = icecream;
}
public void run(){
try{
icecream.IceCre amManFood();
//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.prin tln("butter = " + i);
System.out.prin tln("Totti = " + j);
}
else{
i++;
}}}*/
int i=0;
int j=0;
for(i=0;i<10;i+ +)
for (j = 0; j < 20; j++)
System.out.prin tln( "butterpeca n");
} catch(Interrupt edException ie){
System.err.prin tln(ie.getMessa ge());
}
}
}
class Worker extends Thread {
private IceCream icecream;
public Worker(IceCream kitchen){
this.icecream = kitchen;
}
public void run(){
try{
icecream.Worker Food();
} catch(Interrupt edException ie){
System.err.prin tln(ie.getMessa ge());
}
}
}
class IceCream {
boolean prep = false;
String sale = null;
synchronized public void WorkerFood()thr ows InterruptedExce ption {
if(prep == true){
wait();
}
//sale = "SDA";
prep = true;
System.err.prin tln("Yamyam, ice is ready.");
notifyAll();
}
synchronized public void IceCreamManFood () throws InterruptedExce ption{
if(prep == false){
wait();
}
System.err.prin tln("Food, " + sale + " has been eaten.");
sale = null;
prep = false;
}
}
Comment