Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CSIS 130 American University of Kuwait Lab 9-OOP (Object Oriented Pizza): We are going to implement a simple system that is going to be used

image text in transcribedimage text in transcribed

CSIS 130 American University of Kuwait 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 (Topping0 s); public abstract boolean remove Topping(Topping t); 3) Create a class called NonVegPizza that is a subclass of the Pizza class. The class has the following concrete object variables: a. -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). 2 4) In the NonVegPizza class: Implement the abstract methods from part 2)b). 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. 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. 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 remove Topping method removes a specific topping from the ArrayList and returns true if it is successful, otherwise false. Create a toString method that describes the Pizza by its name and lists the toppings. b. e Ali A. Be hiry Page 1 of 2 CSIS 130 American University of Kuwait 5) Create a class called Veg Pizza 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; 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. b 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 ArrayList 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) Take reminder of the following instructions: 1) Your main class refers to whatever class is named after your Project name. It will contain your main method. 2) You must attend and attempt the lab within the lab time in order to get the lab grade even if the due date is extended after the lab. 3) Only submit.java files on Moodle, no other submissions will be accepted. 4) Late submissions will not be accepted. 5) Insufficient testing will be penalized. 6) Messy code will be penalized. /* To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools Templates * and open the template in the editor. */ package oopizza; /** * * @author alise */ 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[@] = 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); 1/START OF PART 6 1/-- 1/make your own pizza //--- //END OF PART 6 // }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David J. Auer David M. Kroenke

13th Edition

B01366W6DS, 978-0133058352

More Books

Students also viewed these Databases questions

Question

Explain the functions of financial management.

Answered: 1 week ago

Question

HOW MANY TOTAL WORLD WAR?

Answered: 1 week ago

Question

Discuss the scope of financial management.

Answered: 1 week ago

Question

Discuss the goals of financial management.

Answered: 1 week ago

Question

Differentiate between hard and soft measures of service quality.

Answered: 1 week ago

Question

Be familiar with the different perspectives of service quality.

Answered: 1 week ago