Question: 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 delivery 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

I am able to get section 1 and 3 right but I don't know why i can't get the section 2 right. anyone please help me get the section 2 right? thank you.

1:

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;

if(price>15)

this.deliveryFee = 3;

else

this.deliveryFee = 5;

}

public double getDeliveryFee() {

return deliveryFee;

}

public void setDeliveryFee(double deliveryFee) {

this.deliveryFee = deliveryFee;

}

public String getAddress() {

return address;

}

public void setAddress(String address) {

this.address = address;

}

@Override

public String toString() {

return "DeliveryPizza{" +

"deliveryFee=" + deliveryFee +

", address='" + address + '\'' +

'}';

}

}

2:

public class DemoPizzas {

public static void main(String[] args) {

DeliveryPizza pizza1 = new DeliveryPizza("sausage and onion", 14.99, "Street 21, NYC");

pizza1.display();

DeliveryPizza pizza2 = new DeliveryPizza("mozzarella", 18.99, "Street 36, NYC");

pizza2.display();

}

}

3:

public class Pizza {

private String description;

private double price;

public Pizza(String description, double price) {

this.description = description;

this.price = price;

}

public String getDescription() {

return description;

}

public void setDescription(String description) {

this.description = description;

}

public double getPrice() {

return price;

}

public void setPrice(double price) {

this.price = price;

}

public void display() {

System.out.println(description+" Price: $"+price);

}

@Override

public String toString() {

return "Pizza{" +

"description='" + description + '\'' +

", price=" + price +

'}';

}

}

please just see what is wrong in section 2. thank you.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!