Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a class named Pizza with the following data fields: description - of type String price - of type double The description stores the type

Create a class named Pizza with the following data fields:

  • description - of type String
  • price - of type double

The description stores the type of pizza (such as sausage and onion). Include a constructor that requires arguments for both fields and a method named display() to display the data. For example, if the description is 'sausage and onion' and the price is '14.99', the display method should output:

sausage and onion pizza Price: $14.99

Create a subclass named DeliveryPizza that inherits from Pizza but adds the following data fields:

  • deliveryFee - of type double
  • address - of type String

The description, price, and address are required as arguments to the constructor. The delivery fee is $3 if the pizza ordered costs more than $15; otherwise it is $5.

Add a display() method to the DeliveryPizza class. The display() method should print the information from the display() method in the super class (Pizza) in addition to the address and delivery fee.

sausage and onion pizza Price: $14.99 Deliver to: 22 Acorn Street, APT 882. Fee is 5.0

 

My code so far:

public class Pizza

{

protected String description;

protected double price;

public Pizza(String description, double price) {

this.description = description;

this.price = price;

}

public void display() {

System.out.printf("%s pizza Price: $%.2f ", description, price);

}

}

public class DeliveryPizza extends Pizza

{

private double deliveryFee;

private String address;

public DeliveryPizza(String description, double price, String address) {

super(description, price);

this.address = address;

deliveryFee = 5;

if (price > 15) deliveryFee = 3;

}

public void display() {

System.out.printf("%s pizza Price: $%.2f with additional delivery fee of $%.2f will be delivered to %s ", description, price, deliveryFee, address);

}

}

public class DemoPizzas

{

public static void main(String args[])

{

Pizza pizza = new Pizza("sausage and onion", 14.99);

DeliveryPizza deliveryPizza = new DeliveryPizza("sausage and onion", 14.99, "Main street");

pizza.display();

deliveryPizza.display();

}

}

I don't understand where I did it wrong. I keep getting this error pop up saying that I need to define the display method for the Pizza class properly. Please help

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

Learn To Program Databases With Visual Basic 6

Authors: John Smiley

1st Edition

1902745035, 978-1902745039

More Books

Students also viewed these Databases questions