Question
We are going to implement a simple system that is going to be used by a Pizza restaurant to automate their creation of custom pizza and calculation of prices.

1) Create a class called Topping. The class has the following property:

a. Object variables (String) name, (Boolean) veg and (double) price. The veg is a Boolean that is true if the Topping is vegetarian and false otherwise.

b. Create getters and setters for all the above object variables.

c. Create a constructor that sets all the above object variables.

d. Overload the above constructor with a constructor that only sets the name and veg object variables. The price is assumed to be 0.2 if veg is false and 0.1 otherwise.

2) Create an abstract class called Pizza. The class has the following:

a. An static class variable with the following code:

protected static final double[] PRICE_SIZE = {3.0,6.0,7.0};

This will denote the base cost for each of the three pizza sizes: small, medium and large.

b. The following abstract methods to be implemented in subclasses:

public abstract double calcPrice();
public abstract boolean addTopping(Topping t);
public abstract boolean addToppings(Topping[] s);
public abstract boolean removeTopping(Topping t);

3) Create a class called NonVegPizza that is a subclass of the Pizza class. The class has the following concrete object variables:

- An ArrayList of Topping variables. A
- String name that represents the Pizza name.
- int size that denotes the size of the pizza. (0 means small, 1 means medium and 2 means large).

4) In the NonVegPizza class: Implement the abstract methods from part 2) b).

a. The calcPrice method adds the base cost depending on the pizza size to the price of all the toppings on the pizza and returns the total cost.

b. The addTopping method adds the topping to the topping ArrayList and returns true if it is successful., otherwise false. A maximum of 4 toppings is allowed.

c. The addToppings method iterates over ArrayList s of toppings and adds them. It returns true if all toppings can be added successfully, otherwise it returns false.

d. The removeTopping method removes a specific topping from the ArrayList and returns true if it is successful, otherwise false.

e. Create a toString method that describes the Pizza by its name and lists the toppings.

5) Create a class called VegPizza that is a subclass of the NonVegPizza class. overload the class methods from part 3) such that:

a. The addTopping method adds the topping to the topping ArrayList ONLY IF it is a vegetarian option and then returns true. Otherwise it returns false;

b. The addToppings method iterates over ArrayList s of toppings and only adds them all if they’re all vegetarian options and then returns true. Otherwise it returns false.

c. The toString should reflect that this is also a vegetarian pizza as well as the previous information from the super class toString.

6) You have been provided with some testing code in the OOPizza.java file provided. Use the code in that main method in your main class and add your own to create Pizza p4, with your own favourite pizza and toppings. (You can create extra objects if you’d like). Create an ArrayList<Pizza> pizzas and add p1, p2, p3 and p4 to it. Finally: write some code in order to loop through the array list and calculate the sum of the prices of ONLY the vegetarian pizzas in this ArrayList. (Hint: look up and use instanceof)
Solution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references.
Students may use these solutions for personal skill-building and practice.
Unethical use is strictly forbidden.

import java.util.ArrayList;

public class Lab9 {
public static void main(String[] args) {
// TODO code application logic here
Topping pin = new Topping("Pineapple", true);
Topping che = new Topping("Cheese", true, 0.05);
Topping sau = new Topping("Sauce", true, 0.05);
Topping pep = new Topping("Pepperoni", false, 0.4);
Topping bat = new Topping("Bat", false);
Topping pot = new Topping("Boiled Potato", true);

Pizza p1 = new VegPizza("Internet Buster");
System.out.println("Adding " + sau.getName() + ":" + p1.addTopping(sau)); // Should Return True
p1.addTopping(che);
p1.addTopping(pin);
p1.addTopping(pin);
System.out.println("Adding " + pep.getName() + ":" + p1.addTopping(pep)); // Should Return False

Pizza p2 = new NonVegPizza("ELearning Bringer");
Topping[] list = new Topping[3];
list[0] = sau;
list[1] = che;
list[2] = bat;
p2.addToppings(list);
System.out.println(p2.toString());

Pizza p3 = new VegPizza("Sasha Blouse Special");
list = new Topping[5];
list[0] = sau;
list[1] = che;
list[2] = pep; // non-vegetarian
list[3] = pot;
list[4] = pot;
System.out.println(p3.addToppings(list)); // should return false as one of them failed
System.out.println(p3); // Testing the toString
This is only a preview of the solution.
Please use the purchase button to see the entire solution.
By purchasing this solution you'll be able to access the following files:
Solution.zip
Purchase Solution
$50.00 $25
Google Pay
Amazon
Paypal
Mastercard
Visacard
Discover
Amex
View Available Computer Science Tutors 645 tutors matched
Ionut
(ionut)
Master of Computer Science
Hi! MSc Applied Informatics & Computer Science Engineer. Practical experience in many CS & IT branches.Research work & homework
5/5 (6,808+ sessions)
1 hour avg response
$15-$50 hourly rate
Pranay
(math1983)
Doctor of Philosophy (PhD)
Ph.D. in mathematics and working as an Assistant Professor in University. I can provide help in mathematics, statistics and allied areas.
4.6/5 (6,704+ sessions)
1 hour avg response
$40-$50 hourly rate
Leo
(Leo)
Doctor of Philosophy (PhD)
Hi! I have been a professor in New York and taught in a math department and in an applied math department.
4.9/5 (6,469+ sessions)
2 hours avg response

Similar Homework Solutions