Question
JAVA Create a class named Pizza with the following data fields: description - of type String price - of type double The description stores the
JAVA
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
--------------------------------------------
This is what the assignment is looking for:
--------------------------------------------
code to copy:
public class DeliveryPizza
{
String address;
double DeliveryFee;
// Define DeliveryPizza class here
DeliveryPizza(String desc, double pr, String address)
public void display ()
{
super.display();
System.out.println("Deliver to: " + address + ". Fee is" + DeliveryFee);
}
}
code to copy:
public class DemoPizzas
{
public static void main(String args[])
{
// Write demo program here
}
}
code to copy:
public class Pizza
{
// Define the Pizza class here
private String description;
private double price;
public Pizza(String desc, double pr)
{
description = desc;
price = pr;
}
public void display()
{
System.out.println(description + "pizza Price: $" + price);
}
}
Pizza constructor defined Define display method for Pizza class DeliveryPizza constructor defined Define the display method for the DeliveryPizza method. + Delivery Pizza.java Demo Pizzas.java Pizza.java 1 public class Delivery Pizza 2 { 3 String address; double DeliveryFee; 5 6 // Define DeliveryPizza class here 7 DeliveryPizza(String desc, double pr, String address) 4 8 9 10 public void display () 11 { 12 super.display(); 13 System.out.println("Deliver to: + address + ". Fee is" + DeliveryFee); 14 } 15 16 6 17] 18 Delivery Pizza.java Demo Pizzas.java Pizza.java + 1 public class Demo Pizzas 2{ 3 public static void main(String args[]) 4 { 5 // Write demo program here 6 } 7} 5 8 Delivery Pizza.java Demo Pizzas.java Pizza.java + 3 1 public class Pizza 2{ // Define the Pizza class here 4 private String description; private double price; public Pizza(string desc, double pr) 5 6 7 8 8 { 9 10 description = desc; 11 price = pr; 12 13 } 14 15 public void display() 16 { 17 System.out.println(description + "pizza Price: $" + price); 18 } 19 20 } 21
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started