Driver Program

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 1455 Views - Last Post: 29 October 2010 - 01:44 PM Rate Topic: -----

#1 kwjelly20  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 27-September 10

Driver Program

Posted 28 October 2010 - 12:04 PM

Im trying to build a driver class Named restaurant, The purpose is to write a driver class that simulates a restaurant using AutomaticKitchen.class. You have three tables, one with four people, one with 12 people, and one with 1 person. Everyone at a table eats the same thing. Im have no idea what im am doing or where to start can someone guide me in the right direction
public class Resturant {

public static void main (String[] args) {

setNumberServings("");
setIngredients("");
setCookTemp("");
set(1,100);







public class AutomatedKitchen {
    
private int cookTemp;
    
private int cookTime;
    
private String cookedMeal;
    
private boolean healthyFood;
    
private String[] ingredientList;
    
private boolean mealReady;
    
private int nextArrayIndex = 0;
    
private int numberServings;
    
public static final int DEFAULT_COOK_TIME = 30;
    
public static final int DEFAULT_COOK_TEMP = 350;
    
public static final int DEFAULT_NUMBER_SERVINGS = 4;
    
public static final int MAX_INGREDIENTS = 10;
    
public AutomatedKitchen() {
        
ingredientList = new String[10];
        
this.numberServings = DEFAULT_NUMBER_SERVINGS;
        
this.cookTemp = DEFAULT_COOK_TEMP;
        
this.cookTime = DEFAULT_COOK_TIME;
        
this.healthyFood = false;
        
this.mealReady = false;
        
setIngredient("water");
   
 }
    
public void cookMeal(){
        
mealReady = true;
    
}
    
public void serveMeal(){
        
if (mealReady = true) {
            
System.out.print("Serving a meal for " + numberServings + " ");
            if (healthyFood){
                System.out.println("This meal is healthy. ");
            }
            else{
                System.out.println("This meal is unhealthy. ");
            }
            System.out.println("We cooked a blend of ");
            for (int x = 0; x < nextArrayIndex; x++){
                if ( x > 0){
                     if (x < nextArrayIndex -1){
                        System.out.print(", ");
                    }
                    else{
                        System.out.print(" and ");
                    }
                    
                }
                   System.out.println(ingredientList[x]);
            }
            System.out.println(" for " + cookTime + " minutes at " + cookTemp + " degrees.");
            cookTemp(cookTemp);
        }
        
    }
    public int getCookTemp() {
        return cookTemp;
    }
    public void setCookTemp(int i) {
        this.cookTemp = i;
    }
    public int getCookTime() {
        return cookTime;
    
}
    
public void setCookTime(int i) {
        
this.cookTime = i;
    
}
    
public String getCookedMeal() {
        
return cookedMeal;
    
}
    
public void setCookedMeal(String cookedMeal) {
        
this.cookedMeal = cookedMeal;
    
}
    
public boolean getHealthyFood() {
        
return healthyFood;
 
}
    
public void setHealthyFood(boolean bln) {
       
 this.healthyFood = bln;
    
}
    
public void setIngredient(String ingredient) {
        
if (nextArrayIndex < MAX_INGREDIENTS){
            
ingredientList[nextArrayIndex] = ingredient;
        
}
        
this.nextArrayIndex += 1;
    
}
   
 public boolean readyToServe() {
       
 return mealReady;
   
}
    
public void setReadyToServe(boolean mealReady) {
        
this.mealReady = mealReady;
    
}
    
public int getNumberServings() {
        
return numberServings;
    
}
    
public void setNumberServings(int numberServings) {
        
this.numberServings = numberServings;
    
}
    
public int getNumberIngredients(){
        
return nextArrayIndex +1;
    
}




public static void cookTemp(int sign){

    if (sign >=300){
System.out.print("It's five start delicious.");
}
else if ( sign <=250){
System.out.print("It's terrible.");
}
}



public static void main(String [] javaa)
{
		AutomatedKitchen a = new AutomatedKitchen();
		a.cookMeal();
		a.serveMeal();
		
		
		
}
}
  


Is This A Good Question/Topic? 0
  • +

Replies To: Driver Program

#2 SarumanTheWhite  Icon User is offline

  • D.I.C Regular

Reputation: 73
  • View blog
  • Posts: 352
  • Joined: 04-November 08

Re: Driver Program

Posted 28 October 2010 - 12:11 PM

Your driver program is supposed to utilize this AutomatedKitchen class and utilize the methods it provides to do what you were told. In order to start you'll need to create an instance of the class like this:

AutomatedKitchen kitchen = new AutomatedKitchen();



There's a few things to consider when doing this, I'm not to list all possibilities so just research on google or somewhere on more info regarding creating instances of a class or object.

Then to call one of it's methods you would do this

kitchen.setCookTime(100);



That's the basic idea of it.


Edit: I just noticed there's already a main function in your AutomatedKitchen class. Was that placed in there as an example? If you're going to use Restaurant as your driver you're going to want to remove that from AutomatedKitchen.

This post has been edited by SarumanTheWhite: 28 October 2010 - 12:19 PM

Was This Post Helpful? 0
  • +
  • -

#3 kwjelly20  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 27-September 10

Re: Driver Program

Posted 28 October 2010 - 12:30 PM

View PostSarumanTheWhite, on 28 October 2010 - 06:11 PM, said:

Your driver program is supposed to utilize this AutomatedKitchen class and utilize the methods it provides to do what you were told. In order to start you'll need to create an instance of the class like this:

AutomatedKitchen kitchen = new AutomatedKitchen();



There's a few things to consider when doing this, I'm not to list all possibilities so just research on google or somewhere on more info regarding creating instances of a class or object.

Then to call one of it's methods you would do this

kitchen.setCookTime(100);



That's the basic idea of it.


Edit: I just noticed there's already a main function in your AutomatedKitchen class. Was that placed in there as an example? If you're going to use Restaurant as your driver you're going to want to remove that from AutomatedKitchen.


This is what I have did so far. As far as the code im still editing that part as well, does this look correct so far. How do I configure a return for the"state of healthy and return for meal is ready to server.

public class Resturant {

public static void main (String[] args) {

AutomatedKitchen kitchen = new AutomatedKitchen();
kitchen.setNumberServing(4);
kiichen.setNumberIngredients(10)
kitchen.setCookingtemperature(350);
kitchen.setCookTime(30);

kitchen.NumberIngredients();
kitchen.CookTemp();
kitchen.CookTime();



Was This Post Helpful? 0
  • +
  • -

#4 SarumanTheWhite  Icon User is offline

  • D.I.C Regular

Reputation: 73
  • View blog
  • Posts: 352
  • Joined: 04-November 08

Re: Driver Program

Posted 28 October 2010 - 12:40 PM

Well it looks like those methods are already written for you I see getHealthyFood and setHealthyFood, as well as readyToServe which returns a boolean so you'll most likely be using that in an if statement. You also have to consider that some of those methods return values. To get them you'll do something like:

variablename = kitchen.getHealthyFood();



That's how to pass those around, other than that I'm not sure what you're asking.
Was This Post Helpful? 0
  • +
  • -

#5 kwjelly20  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 27-September 10

Re: Driver Program

Posted 28 October 2010 - 12:47 PM

View PostSarumanTheWhite, on 28 October 2010 - 06:40 PM, said:

Well it looks like those methods are already written for you I see getHealthyFood and setHealthyFood, as well as readyToServe which returns a boolean so you'll most likely be using that in an if statement. You also have to consider that some of those methods return values. To get them you'll do something like:

variablename = kitchen.getHealthyFood();



That's how to pass those around, other than that I'm not sure what you're asking.


Quote

Im sorry about that, this is what im trying to do is return these below, I should have been a little clearer in regards to my question. I'm not sure how to construct this within the driver to out wheter false and or give a return:
//sets the healthy option. Default is false
public void setHealthyFood(boolean)

//returns the state of the healthy option
public boolean getHealthyOption()

//required to prepare a meal before itís served.
public void cookMeal()

//returns if a meal is ready to serve. Default is false.
public boolean readyToServe()

//returns a string that is the formatted report of the meal that is served, then sets the object state so that the meal is not ready to serve and must be cooked again.
public String serveMeal()

// end of API

Was This Post Helpful? 0
  • +
  • -

#6 SarumanTheWhite  Icon User is offline

  • D.I.C Regular

Reputation: 73
  • View blog
  • Posts: 352
  • Joined: 04-November 08

Re: Driver Program

Posted 28 October 2010 - 01:11 PM

So you're not sure when to provide true or false for the given methods? I'd assume that depends on the Person who asks for it ( perhaps there needs to be a Person class to represent a customer? ) within the simulation. Otherwise I would just put anything since it's a mere simulation but that really depends on the requirements of your assignment. The methods cookMeal(), readyToServe() and serveMeal() should be self explanatory unless you're not sure how to use 'em.

The logic should be something like

if(kitchen.readToServe())
  kitchen.serveMeal();
else
  kitchen.cookMeal();


Was This Post Helpful? 0
  • +
  • -

#7 kwjelly20  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 27-September 10

Re: Driver Program

Posted 28 October 2010 - 03:32 PM

View PostSarumanTheWhite, on 28 October 2010 - 07:11 PM, said:

So you're not sure when to provide true or false for the given methods? I'd assume that depends on the Person who asks for it ( perhaps there needs to be a Person class to represent a customer? ) within the simulation. Otherwise I would just put anything since it's a mere simulation but that really depends on the requirements of your assignment. The methods cookMeal(), readyToServe() and serveMeal() should be self explanatory unless you're not sure how to use 'em.

The logic should be something like

if(kitchen.readToServe())
  kitchen.serveMeal();
else
  kitchen.cookMeal();


How is kitchen.serveMeal() returned im not seeing any output

public class Restaurant {

public static void main (String[] args) {

AutomatedKitchen kitchen = new AutomatedKitchen();
kitchen.setNumberServings(4);
kitchen.setIngredient("water");
kitchen.setCookTemp(350);
kitchen.setCookTime(30);

kitchen.getNumberIngredients();
kitchen.getCookTemp();
kitchen.getCookTime();
kitchen.readyToServe()

 




if(kitchen.readyToServe())
kitchen.serveMeal(); 

else
  kitchen.cookMeal();
 return;


Was This Post Helpful? 0
  • +
  • -

#8 kwjelly20  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 27-September 10

Re: Driver Program

Posted 29 October 2010 - 11:51 AM

View Postkwjelly20, on 28 October 2010 - 09:32 PM, said:

View PostSarumanTheWhite, on 28 October 2010 - 07:11 PM, said:

So you're not sure when to provide true or false for the given methods? I'd assume that depends on the Person who asks for it ( perhaps there needs to be a Person class to represent a customer? ) within the simulation. Otherwise I would just put anything since it's a mere simulation but that really depends on the requirements of your assignment. The methods cookMeal(), readyToServe() and serveMeal() should be self explanatory unless you're not sure how to use 'em.

The logic should be something like

if(kitchen.readToServe())
  kitchen.serveMeal();
else
  kitchen.cookMeal();


How is kitchen.serveMeal() returned im not seeing any output

public class Restaurant {

public static void main (String[] args) {

AutomatedKitchen kitchen = new AutomatedKitchen();
kitchen.setNumberServings(4);
kitchen.setIngredient("water");
kitchen.setCookTemp(350);
kitchen.setCookTime(30);

kitchen.getNumberIngredients();
kitchen.getCookTemp();
kitchen.getCookTime();
kitchen.readyToServe()

 




if(kitchen.readyToServe())
kitchen.serveMeal(); 

else
  kitchen.cookMeal();
 return;



Does anyone have any suggestions as to methods of returns the kitchen.serveMeal():
Was This Post Helpful? 0
  • +
  • -

#9 SarumanTheWhite  Icon User is offline

  • D.I.C Regular

Reputation: 73
  • View blog
  • Posts: 352
  • Joined: 04-November 08

Re: Driver Program

Posted 29 October 2010 - 11:55 AM

serveMeal() is void. It returns nothing. All it does is output messages to the console based on certain values.
Was This Post Helpful? 0
  • +
  • -

#10 kwjelly20  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 27-September 10

Re: Driver Program

Posted 29 October 2010 - 12:08 PM

View PostSarumanTheWhite, on 29 October 2010 - 05:55 PM, said:

serveMeal() is void. It returns nothing. All it does is output messages to the console based on certain values.


Yes, I understand that but the program isnt compiling at all nor is it giving any errors, I tried declaring this but I recieved errors by doing this; so I was thinking that I declared this wrong causing the program to compile but not exceuting anything.
public class Restaurant {

public static void main (String[] args) {

AutomatedKitchen kitchen = new AutomatedKitchen();
kitchen.setNumberServings(4);
kitchen.setIngredient("water");
kitchen.setCookTemp(350);
kitchen.setCookTime(30);

kitchen.getNumberIngredients();
kitchen.getCookTemp();
kitchen.getCookTime();
kitchen.getserveMeal();





if(kitchen.readyToServe())
kitchen.serveMeal(); 

else
  kitchen.cookMeal();
 return;


  


} // end of main() method
} // end of API




See attached picture

Attached ImageAttached Image

View Postkwjelly20, on 29 October 2010 - 06:05 PM, said:

View PostSarumanTheWhite, on 29 October 2010 - 05:55 PM, said:

serveMeal() is void. It returns nothing. All it does is output messages to the console based on certain values.


Yes, I understand that but the program isnt compiling at all nor is it giving any errors, I tried declaring this but I recieved errors by doing this; so I was thinking that I declared this wrong causing the program to compile but not exceuting anything.
public class Restaurant {

public static void main (String[] args) {

AutomatedKitchen kitchen = new AutomatedKitchen();
kitchen.setNumberServings(4);
kitchen.setIngredient("water");
kitchen.setCookTemp(350);
kitchen.setCookTime(30);

kitchen.getNumberIngredients();
kitchen.getCookTemp();
kitchen.getCookTime();
kitchen.getserveMeal();





if(kitchen.readyToServe())
kitchen.serveMeal(); 

else
  kitchen.cookMeal();
 return;


  


} // end of main() method
} // end of API




See attached picture

This post has been edited by kwjelly20: 29 October 2010 - 12:06 PM

Was This Post Helpful? 0
  • +
  • -

#11 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10766
  • View blog
  • Posts: 40,088
  • Joined: 27-December 08

Re: Driver Program

Posted 29 October 2010 - 12:17 PM

View Postkwjelly20, on 29 October 2010 - 03:08 PM, said:

Yes, I understand that but the program isnt compiling at all nor is it giving any errors, I tried declaring this but I recieved errors by doing this;


You are getting errors or you aren't? If your code won't compile, you will get errors.
Was This Post Helpful? 0
  • +
  • -

#12 SarumanTheWhite  Icon User is offline

  • D.I.C Regular

Reputation: 73
  • View blog
  • Posts: 352
  • Joined: 04-November 08

Re: Driver Program

Posted 29 October 2010 - 12:19 PM

Read what serveMeal does very carefully. It will only carry out it's output if mealReady is set to true, and the only way to do that is to call cookMeal(). So when cookMeal() is called, call serveMeal() afterwards.
Was This Post Helpful? 0
  • +
  • -

#13 kwjelly20  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 27-September 10

Re: Driver Program

Posted 29 October 2010 - 12:22 PM

View Postmacosxnerd101, on 29 October 2010 - 06:17 PM, said:

View Postkwjelly20, on 29 October 2010 - 03:08 PM, said:

Yes, I understand that but the program isnt compiling at all nor is it giving any errors, I tried declaring this but I recieved errors by doing this;


You are getting errors or you aren't? If your code won't compile, you will get errors.

The code is compiling but not executing, my teacher wrote this to me as a response, but im not understanding which way would be the correct way to implement

"This method:
kitchen.serveMeal();

Has a return type. You need to do something with the data thatís returned in order to get it to show on the screen.
"
Was This Post Helpful? 0
  • +
  • -

#14 SarumanTheWhite  Icon User is offline

  • D.I.C Regular

Reputation: 73
  • View blog
  • Posts: 352
  • Joined: 04-November 08

Re: Driver Program

Posted 29 October 2010 - 12:48 PM

Let me try and run down what you have so far.

AutomatedKitchen kitchen = new AutomatedKitchen();
kitchen.setNumberServings(4);
kitchen.setIngredient("water");
kitchen.setCookTemp(350);
kitchen.setCookTime(30);



Alright, so you're setting some data for a particular cook job. Seems alright to me. But according to your directions:

"You have three tables, one with four people, one with 12 people, and one with 1 person. Everyone at a table eats the same thing."

It looks to me you're going to have different cooking processes depending on these different people. Like I said earlier, this leads me to believe there may need to be an extra class that represents a Person that holds data about their preferences and whatnot. Then there will probably be a few arrays of these People objects to represent tables. Sounds like a loop comes into play here. But that's just me, I have no clue what your instructor wants.

kitchen.getNumberIngredients();
kitchen.getCookTemp();
kitchen.getCookTime();
kitchen.getserveMeal();



You're essentially doing nothing useful here. You're calling the getter for these variables, but what are you storing their return value into? Nothing from the looks of it. You'll only want to call a get function when you want to store it's output into a variable somewhere or perhaps pass it into the parameters of a method, or other things.

if(kitchen.readyToServe())
kitchen.serveMeal(); 

else
  kitchen.cookMeal();
 return;



So here you want basically to say IF the meal is ready to serve THEN serve it IF NOT ELSE cook it as well as serve it.

You need to develop a process that makes sense and plan out how it's going to work and implement it.
Was This Post Helpful? 0
  • +
  • -

#15 kwjelly20  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 27-September 10

Re: Driver Program

Posted 29 October 2010 - 01:07 PM

The portion list above is correct, but where im lost is the last portion following

Quote

"//returns a string that is the formatted report of the meal that is served, then sets the object state so that the meal is not ready to serve and must be cooked again.
public String serveMeal()"


I not sure if I can even make a string within a driver program. Which has me trumpled. I know that when declared it produces errors upon compiling. String serveMeal() doesnt do much in the closing portion
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2