Question
Java coding package oopizza; /** * * @author */ public class OOPizza { /** * @param args the command line arguments */ public static void
Java coding
package oopizza;
/** * * @author */ public class OOPizza {
/** * @param args the command line arguments */ 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; /on-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 System.out.println("Adding " + pot.getName() + ":" + p3.addTopping(pot)); //Should Return false as it is an extra thing (limit is 4) System.out.println(p3); //------------------------------------------------------------------- //START OF PART 6 //------------------------------------------------------------------- //make your own pizza //------------------------------------------------------------------- //END OF PART 6 //------------------------------------------------------------------- }
}
Lab 9-OOP (Object Oriented Pizza): 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 Nonveg Pizza 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. (O 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 ArrayLists 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 Veg Pizza that is a subclass of the NonVeg Pizza 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 ArrayLists 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 on Moodle. 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 ArrayListStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started