Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given the code below answer these questions. A. What makes the Pizza class abstract? B. In the Pizza class some variables are defined as being

image text in transcribedimage text in transcribedimage text in transcribed

Given the code below answer these questions. A. What makes the Pizza class abstract? B. In the Pizza class some variables are defined as being protected and others are defined as being private, what is the difference. What would change in the Small_Pizza class if private was used for the variable cost. C. In the compareTo method, how does the compiler know that only objects of type Pizza will be compared? D. In the class Pizza, which variables are class variables as opposed to instance variables? E. Name all the constructors that get invoked with this statement. Small_Pizza sm_pizza = new Small_Pizza(); F. A large pizza costs 10 dollars and each topping on the large pizza costs 75. Write the class for the large pizza which builds from the existing Pizza class. H 1 public class Pizzadrv { 2 public static void main(String[] args) { 3 Small_pizza sm_pizza = new Small_pizza(); 4 Pizza[] pizzas = new Pizza[4]; 5 pizzas [0] = sm_pizza; 6 } 7 } // end of Pizzadrv 8 abstract class Pizza implements Comparable 9 { 10 protected String size; 11 private Date time_ordered; 12 protected double cost; 13 protected String toppings; 14 public static String store = "Vinny's"; 15 16 public Pizza() { 17 size = ""; 18 cost = 0; 19 } 20 public Pizza (String size) { this.size = size; 22 time_order = new java.util.Date(); 23 toppings = ""; 24 1 public String get_size() { return this.size; } 21 25 26 27 public abstract void add_topping (String topping); public double get_cost() { return this.cost; | public void set_cost (double cost) { this.cost = cost; } 28 29 30 31 32 33 34 35 36 37 38 39 40 41 public int compareTo (Pizza sp) { if (size.equals IgnoreCase (sp.size)) { if (cost sp.cost) return 1; else return 0; } return 1; } public String get_order() { return ("A" + size + pizza " + "was ordered and costs } } // end of Pizza + cost); 42 43 45 class Small_Pizza extends Pizza { 46 public Small_Pizza () { 47 super ("small"); 48 cost = 8; 49 } 50 public void add_topping (String topping) { 51 toppings += " " + topping; 52 cost += .25; 53 } 54 } // end of Small_Pizza 55 56 000 OHM LO

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

Murach's SQL Server 2012 For Developers

Authors: Bryan Syverson, Joel Murach, Mike Murach

1st Edition

1890774693, 9781890774691

More Books

Students also viewed these Databases questions