“Gola Ganda” shop, Gola Gandas of all shapes and sizes. Gola gandas of three sizes: Small, Medium and Large.
A customer can add as many toppings on it as they want, the toppings could be more “Sauce”, Condensed Milk, Nutella, etc . Every topping has a different cost, and the cost of each topping will be added on top of the cost of the size of gola ganda.
if a small gola ganda cost, 50 rupees, and a topping of condensed milk cost 10 rupees, and a topping of Nutella cost 20 rupees, and if a customer has ordered a small gola ganda with condensed milk and Nutella then the total cost will be 80 rupees (50 for small gola ganda, 10 for condensed milk, and 20 for Nutella).
Your job is to design a system that can calculate the final cost of the gola ganda.
task is the following:
• Identify the design pattern that can be used over here
• Justify your choice
• Make a class diagram (using UML Notation)
• Implement the classes in JAVA
• Test your implementation
// The pattern Builder is used because of usage of several step by step
// operations to build the whole object
import java.util.ArrayList;
import java.util.HashMap;
public class GolaGanda {
int size;
double price;
ArrayList<String> topping = new ArrayList<String>();
static HashMap<String, Double> toppings = new HashMap<String, Double>();
static {
toppings.put("Condensed milk", 10.0);
toppings.put("Nutella", 20.0);
toppings.put("Sauce", 8.50);
}// add
GolaGanda(int s, double p, ArrayList<String> tps )
{size = s;
price = p;
topping.addAll(tps);}
class GolaGandaCooker implements Cooker{
int size;
double price;
ArrayList<String> topping;
@Override
public void setSize(int s) { //-0
size = s;
if (size < 10)
price +=50;
else if (size < 30)
price += 70;
else price = 100;
}
@Override
public void addToppings(String top) {
topping.add(top);
price += toppings.get(top);
}
@Override
public GolaGanda getResult() {
return new GolaGanda(size, price, topping);
}}
}
interface Cooker {
void setSize(int s);
void addToppings(String top);
GolaGanda getResult();
}
Comments
Leave a comment