Question

In: Computer Science

Java Code. imagine you're working for a fast-food restaurant. get details returns name of the burger...

Java Code. imagine you're working for a fast-food restaurant. get details returns name of the burger and getPrice return the price of the meal.

Using Decorator pattern make class BurgerToppings:

-Each topping is an extra $1 and the name provided in the constructor

-getTotalPrice: returns total price of burger + toppings

-getDetails: returns the burger name + name of topping with the word (extra)

Code:

public interface Burger{
    double C();
    String getDetails();
}
public class BigMac implements Burger{
    private String order;
    private double price ;

    public BigMac() {
        this.order= "Big Mac";
        this.price = 4.00;
    }

    @Override
    public double getPrice() {
        return price;
    }

    @Override
    public String getorder() {
        return name;
    }
}

Output expected:

Ordering BigMac + extra pickles+ extra cheese
Total price = 6.0

Solutions

Expert Solution

CODE :

Burger.java

package c15;
public interface Burger{
double getPrice();
String getorder();
}

BurgerToppings.java

package c15;

public class BurgerToppings {
private String name;
BurgerToppings(String n){
name = n;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

BigMac.java
PROGRAM :

package c15;

import java.util.ArrayList;

public class BigMac implements Burger{
private String order;
private double price;
private ArrayList<BurgerToppings> toppings;

public BigMac() {
this.order= "Big Mac";
this.price = 4.00;
toppings = new ArrayList<BurgerToppings>();
}

void addTopping(String top) {
toppings.add(new BurgerToppings(top));
}
@Override
public double getPrice() {
// TODO Auto-generated method stub
return 0;
}

@Override
public String getorder() {
String topping="";
for(BurgerToppings t : toppings) {
topping += " Extra "+t.getName();
}
return order+topping;
}


public double getTotalPrice() {
double top=toppings.size();
return top+price;
}


public static void main(String[] args) {
BigMac mac = new BigMac();
mac.addTopping("Cheese");
mac.addTopping("pickles");
System.out.println("Ordering "+mac.getorder());
System.out.println("Total price = "+mac.getTotalPrice());
}
}

OUTPUT :
Ordering Big Mac Extra Cheeese Extra PiCkles
Total Price = 6.0


Related Solutions

Imagine you're working for a fast-food restaurant. get details returns name of the burger and getPrice...
Imagine you're working for a fast-food restaurant. get details returns name of the burger and getPrice return the price of the meal. Java Using Decorator pattern make class BurgerToppings: -Each topping is an extra $1 and the name provided in the constructor -getTotalPrice: returns total price of burger + toppings -getDetails: returns the burger name + name of topping with the word (extra) Output expected: Ordering BigMac + extra pickles+ extra cheese Total price = 6.0 public interface Burger{ double...
For python! You walk into a fast food restaurant and order fries, a burger, and a...
For python! You walk into a fast food restaurant and order fries, a burger, and a drink. Create a simple text based user interactive program keeps track of the menu items you order. Use a dictionary to keep track of your menu items and price and another dictionary to keep track of your order and quantity.  Fries are $3.50  Burger are $5.00  Drinks are $1.00  Sales tax rate is 7.25% menu = { "burger":5.00, "fries":3.50, "drink":1.00...
Burger King is a fast food restaurant that were in Indonesia in the 1990s re-emerged in...
Burger King is a fast food restaurant that were in Indonesia in the 1990s re-emerged in the country's culinary market. The retail company, PT Mitra Adiperkasa Tbk (MAP) is now the largest fast food restaurant licensee in the US and their competitor is McDonald. MAP added a new subsidiary on behalf of PT Sari Burger Indonesia to manage Burger King. MAP opened Burger King outlets in mid-2007. In their website, Burger King state that : Every day, more than 11...
A fast-food restaurant uses an average of 110 grams of meat per burger patty. Suppose the...
A fast-food restaurant uses an average of 110 grams of meat per burger patty. Suppose the amount of meat in a burger patty is normally distributed with a standard deviation of 20 grams. What is the probability that the average amount of meat in four randomly selected burgers is less than 105 grams?
Question is the following: Arena advertising: Burger Bills, a national fast food restaurant, purchases advertising rights...
Question is the following: Arena advertising: Burger Bills, a national fast food restaurant, purchases advertising rights to advertise in-ice during hockey games at Jensen Arena. Recall that Jensen Arena is still owned by the town of Springfield. In exchange for $60,000 per season, Burger Bills's logo will be displayed in the center ice for all games held at the Arena for 2 consecutive seasons. Burger Bill must pay for this rights at the beginning of each season. Four logos are...
The Research Process Imagine you are in a fast-food restaurant where a lady tells you that...
The Research Process Imagine you are in a fast-food restaurant where a lady tells you that she had heard there was a gene for liking or hating the taste of cilantro. You looked on the Internet to investigate this statement, and although you found similar comments on reputable websites, you are yet to find any scientific studies supporting this claim. Should you be skeptical about the scientific merit of this claim after browsing the Internet? Why? Do you think there...
A fast-food restaurant determines the cost and revenue models for its hamburgers. A fast-food restaurant determines...
A fast-food restaurant determines the cost and revenue models for its hamburgers. A fast-food restaurant determines the cost and revenue models for its hamburgers. C = 0.8x + 7100,     0 ≤ x ≤ 50,000 R = 1 10,000 (66,000x − x2),     0 ≤ x ≤ 50,000 (a) Write the profit function for this situation. P =   (b) Determine the intervals on which the profit function is increasing and decreasing. (Enter your answers using interval notation.) increasing     decreasing     (c) Determine how many hamburgers...
Stephanie and Peyton are working the midnight shift at a fast-food restaurant, where they make slightly...
Stephanie and Peyton are working the midnight shift at a fast-food restaurant, where they make slightly above the national minimum wage. Business is slow, and they begin discussing income inequality after a Mercedes SUV full of college-aged kids comes through the drive-thru for burgers and shakes. Stephanie believes that the growing disparity between the rich and the poor is wrong: “It’s just not fair that people like us are poor and often out of work, while millionaires and their kids...
Velocity, a consulting firm, enters into a contract to help Burger Boy, a fast-food restaurant, design a marketing strategy to compete
Velocity, a consulting firm, enters into a contract to help Burger Boy, a fast-food restaurant, design a marketing strategy to compete with Burger King. The contract spans eight months. Burger Boy promises to pay $60,000 at the beginning of each month. At the end of the contract, Velocity either will give Burger Boy a refund of $20,000 or will be entitled to an additional $20,000 bonus, depending on whether sales at Burger Boy at yearend have increased to a target level. At the inception of...
Problem 4 Imagine that you own a restaurant named Ibra Fast Food. Prepare an imaginary list...
Problem 4 Imagine that you own a restaurant named Ibra Fast Food. Prepare an imaginary list of examples of the following: a. Revenues (1) b. Fixed Costs per (at list 3 examples) c. Variable Costs (at list 3 examples) d. Number of units Once these costs have been determined, find the following; • The Total Cost Equation • The Total Profit • The CM • The CM Ratio • The Break-Even Point in Sales / Dollars • The Break-Even Point...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT