Question: Java progamming Elcipse IDE (50 points) Successfully implement the Hungry Bakery Flow as outlined a. (20 points) Making Items: Correctly storing name and price b.
Java progamming Elcipse IDE (50 points) Successfully implement the Hungry Bakery Flow as outlined a. (20 points) Making Items: Correctly storing name and price
b. (20 points) Eating Items: Correctly tracking the users bill
c. (5 points) Exiting gracefully: Correctly printing final bill
d. (5 points) Output all of these strings in the EXACT format specified in the examples.
Successfully implement the new functionality as outlined below
Track portions of each BakedGood using the new BakedGood class I provided and display them as part of the list of available BakedGoods.
Remove BakedGoods from the list to purchase when they are fully consumed (ie, no more portions are left).
2. (30 points) Use the following programming tools correctly a. (20 points) Choose the appropriate array strategy (over-sized or perfect-sized) array to store the frequencies.
b. (10 points) Complete and use to the toPrettyString method in the BakedGood java class. You are going to write software to manage a bakery. You will allow the user to add a menu item my making it, or purchase an item and track an overall bill for the customer. To do this, you will need to use my BakedGood class, which is provided in the zip and mostly written for you. You will interact with the user to get details of BakedGood items (name and price) that the user wants to sell. You will use the BakedGood items and an array or ArrayList to keep track of these items. When the user wants to buy an item, you will display all of the available items (or an error if no items have been made yet). The user can make and eat as many items as they like, and when they quit you will display their full bill. Below is a basic run-through of the program, illustrating the output your program should provide: (Note: the underlined/green items are what the user will enter, your program should not print these items). A few items items to consider:
1. You will need to use the BakedGood class that I am providing to you. This class is complete except for one method: toPrettyString. This is the method you will call from the main method to output each available BakedGood to the user and that format is shown in a comment in the code. You will have to complete this method for your code to work. You may choose alter this class as much as you like as long as the input/output remains intact, but do not change the class name.
2. Once an item is made, you can assume an infinite number of portions are available, so you do not need to remove anything from the list of available BakedGoods. 3. If the user tries to eat a BakedGood before anything is made, you will need to display the error: There is no food to eat! You have to make some first.
I have provided a new BakedGood class that contains a new portionsLeft variable. You will update your code to ask the user for this information, and then track each time a user eats that item to reduce the number of portionsLeft. When all of the portions are gone for a BakedGood object, you will remove it completely from the list.
This is what shoud be printed to the console with user entering letters and menu items
Welcome to the Hungry Bakery! Would you like to (m)ake or (e)at a BakedGood, or (q)uit? user enters 'm'
What is the name of the BakedGood? user enters 'Cookie'
What is the cost of the BakedGood? user enters '10.50'
How many portions are in this BakedGood? user enters '2'
Would you like to (m)ake or (e)at a BakedGood, or (q)uit? user enters 'e'
Which item do you want to eat? 0) Cookie(2) - 10.5 user enters '0'
Would you like to (m)ake or (e)at a BakedGood, or (q)uit? user enters 'e' // also on my code after the user makes an item this message gets printed twice
Which item do you want to eat? 0) Cookie(1) - 10.5 user enters '0' //This is where my code is messed up becasue I don't get a list of the items printed
Would you like to (m)ake or (e)at a BakedGood, or (q)uit? user enters 'e' There is no food to eat! You have to make some first
Would you like to (m)ake or (e)at a BakedGood, or (q)uit? user enters 'q'
Thank you for stopping by! Your bill is: 21.0
This is my code that compiles, but does not have the portions part added and will not print out what items are on the menu ie. when the sample output says what item do you want to eat that is all i get instead of that and a list of the items along with it in the pretty string format.
/* * The BakedGood Class contains two data elements: the name of the BakedGood and * it's price. The class has a toPrettyString method which must be written by * the student for the project to work. * * /
public class BakedGood {
private String name; private double price; private int portionsLeft; /*----------------------------------------------------------------------- * Constructors There are two constructors for a BakedGood. The first one * takes in no parameters. It sets the name to "", the price to $0.00, and * the portionsLeft to 0. The second one takes in three parameters and sets * the name, price, and portionsLeft accordingly. */
BakedGood() {
name = "";
price = 0.0;
portionsLeft = 0;
}
BakedGood(String name, double price, int portionsLeft)
{
this.name = name;
this.price = price;
this.portionsLeft = portionsLeft;
} // ============================================ // Getters and Setters
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
} // Notice: There is no getter for the PortionsLeft field. // Use the other methods below to interact with this variable.
public void setPortionsLeft(int portionsLeft) {
this.portionsLeft = portionsLeft;
} // ============================================ // ============================================ // Other Helpful Methods ====================== /* * This method reduces the number of portions of this BakedGood object by 1. */
public void eatPortion() {
portionsLeft--;
} /* * This method returns true when this BakedGood has been consumed. In other * words, when the portionsLeft is 0. */
public boolean isGone() {
return portionsLeft == 0; }
class Bakery {
// making a new class to account for the bill and an // array list for the items made
private final ArrayList items;
private double bill;
public Bakery() {
items = new ArrayList<>(10);
bill = 0.0; }
public void addToItems(String name, double price) {
items.add(new BakedGood(name, price));
// an item contains a // name and price
}
public double addToBill(int num) {
bill += items.get(num).getPrice(); return bill; }
public String itemsToString() {
String one = "";
for (int i = 0; i < items.size(); i++) {
// using the pretty string method to display the menu
one += items.get(i).toPrettyString(i) + " ";
} return one;
}
} public static void main(String[] args) {
String name;
double price = 0.0;
double bill = 0.0;
boolean cont = true;
Scanner scan = new Scanner(System.in);
BakedGood b = new BakedGood();
Bakery Bakery = b.new Bakery();
System.out.println("Welcome to the Hungry Bakery!");
do {
/* * I used breaks and switches which I learned from computing * 2402 because I thought it would be more concise than a series * of if statements in a while loop */
System.out.println("Would you like to (m)ake or (e)at a BakedGood, or (q)uit?");
switch (scan.nextLine()) {
case "m":
System.out.println("What is the name of the BakedGood?");
name = scan.next();
System.out.println("What is the cost of the BakedGood?");
price = scan.nextDouble();
Bakery.addToItems(name, price);
// adding the name and cost // of item to the menu
break;
case "e":
if (price == 0.0) {
System.out.println("There is no food to eat! You have to make some first.");
break;
}
System.out.println("Which item do you want to eat " + Bakery.items.toString() + "");
bill = bill + Bakery.addToBill(Integer.parseInt(scan.nextLine()));
// printing the bill as an integer in the pretty string format
System.out.println("Bill so far: " + bill);
break;
case "q":
cont = false; default: break;
}
}
while (cont);
System.out.println("Thank you for stopping by!");
System.out.println("Your bill is: " + bill);
} /
* * Project 5X TODO: Write this method This method takes in an int that needs * to be printed at the start of the line like in this example below: * 3) Cake(5) - 1.2 * Note: The number of digits after the decimal place does not matter. */
public String toPrettyString(int index) {
return "";
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
