Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that computes the cost of choosing a pizza using Object Oriented Programming. Must use the template given below import java.util.ArrayList; // Change

Write a program that computes the cost of choosing a pizza using Object Oriented Programming. Must use the template given below

import java.util.ArrayList; // Change the class type if required. public class Pizza { private static final double costOfTopping = 2.5; // Price of Small, medium and large pizza is 10$, 12$ and 14$ respectively. private double[] PriceOfBasePizza = {10.00, 12.00, 14.00}; private double TotalCost; private String type; protected ArrayList toppings = new ArrayList(); private String size; //Initialize the default constructor for this class. public Pizza(String type, String size) { this.type = type; this.size = size; } /* Generate Setters and getters for the variables which you will be requiring later */ public abstract void getToppings(); //Override the toString() method here. } public interface PizzaPrice { public double PriceofSmallPizza(double cost); public double PriceofMediumPizza(double cost); public double PriceofLargePizza(double cost); } // Change, if required with inheritance and interface. public class Regular { public Regular(String type, String size) { super(type, size); // TODO Auto-generated constructor stub } /*Define the toppings here, ask the user, max 2 toppings allowed for Regular type pizza. Populate your ArrayList of Toppings defined in Pizza class in here. Also compute here the total cost of ordering the extra toppings. */ @Override public void getToppings() { Scanner in = new Scanner(System.in); System.out.println("How many toppings would you like?"); int numToppings = in.nextInt(); } /*Implement the PizzaPrice Interfaces methods here to find the price of each pizza by its size using the cost of toppings. One of the method is implemented for your reference. */ @Override public double PriceofSmallPizza(double costTopping) { // TODO Auto-generated method stub return costTopping*this.getPriceOfBasePizza ()[0]; } } // Change, if required with inheritance and interface. public class Feast { public Feast(String type, String size) { super(type, size); // TODO Auto-generated constructor stub } /*Define the toppings here, ask the user, max 3 toppings allowed for Feast type pizza. Populate your ArrayList of Toppings defined in Pizza class in here. Also compute here the total cost of ordering the extra toppings. */ @Override public void getToppings() { Scanner in = new Scanner(System.in); System.out.println("How many toppings would you like?"); int numToppings = in.nextInt(); } /*Implement the PizzaPrice Interfaces methods here to find the price of each pizza by its size using the cost of toppings. One of the method is implemented for your reference. */ @Override public double PriceofSmallPizza(double costTopping) { // TODO Auto-generated method stub return costTopping*this.getPriceOfBasePizza ()[0]; } } import java.util.Scanner; public class PizzaShop { public static void main(String[] args) { // ask for customer name, type and size of pizza. Scanner in = new Scanner(System.in); System.out.println("Enter customer name: "); String name = in.nextLine(); System.out.println("What type of pizza would you like, regular or feast "); String type = in.nextLine(); System.out.println("What size of pizza would you like, small, medium or large? "); String size = in.nextLine(); /* Find total price of pizza as per selection of the user for each pizza type. [5 Marks] */ if (type.equalsIgnoreCase("regular")){ } if(type.equalsIgnoreCase()){ } /* Finally call the toString() method from your Pizza Class and modify it to display the customer name, their type, size and toppings and the total cost of the pizza. */ } }

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

Step: 3

blur-text-image

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

Introductory Relational Database Design For Business With Microsoft Access

Authors: Jonathan Eckstein, Bonnie R. Schultz

1st Edition

1119329418, 978-1119329411

Students also viewed these Databases questions

Question

How does cost-based pricing differ from value-based pricing?

Answered: 1 week ago

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago