Question

using C# language This program will demonstrate inheritance. Your Pizza Shop expands and now handles delivery...

using C# language

This program will demonstrate inheritance. Your Pizza Shop expands and now handles delivery orders and sit down orders in a restaurant setting. There are differences in a SeatedPizzaOrder and a DeliveryPizzaOrder. These are more specialized versions of the PizzaOrders you have been creating all along and you decide to write a program that handles them the same as much as possible and reuses the code of a general PizzaOrder class as much as possible to demonstrate inheritance.

Create a PizzaOrder Class. This class should have the following properties (and their underlying protected variables): Size {of type int}, Toppings {of type String}, Price {of type Decimal}. Make a full constructor for the class that takes all three values, and a default constructor that initializes the basic pizza as a 12 inch cheese pizza for $8. Make sure to include validation in your Size and Price properties and constructor to prevent a change to Size that would be less than 12 or greater than 16, and prevent a change to Price that would be less than 0.

Create a class that inherits from your PizzaOrder class called SeatedPizzaOrder. SeatedPizzaOrder has the three data values that any PizzaOrder has (size, toppings, and price) but also has a tablenumber (of type integer) and serverName (of type string) which allows you to track where the pizza is going and who took the order in the restaurant

Create a class that inherits from your PizzaOrder class called DeliveryPizzaOrder. DeliveryPizzaOrder has the three data values that any PizzaOrder has (size, toppings, and price) but also has a driverName (of type string) which allows you to track who is delivering the pizza.

The main() for this program should allow the user to enter in the values for a SeatedPizzaOrder and the values for a DeliveryPizzaOrder, and after creating an object of each one, it should displays their values (from the created objects) for the user.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

class PizzaOrder
{
protected int size;
private decimal price;
protected string toppings;

public int Size
{
get { return size; }
set
{
if (value < 12 || value > 16)
return;
size = value;
}
}


public decimal Price
{
get { return price; }
set
{
if (value < 0)
return;
price = value;
}
}

public string Toppings
{
get { return toppings; }
set { toppings = value; }
}

public PizzaOrder()
{
price = 8;
size = 12;
toppings = "Cheese";
}

public PizzaOrder(string topp,int siz,decimal prce)
{
toppings = topp;
Size = siz;
Price = prce;
}

public override string ToString()
{
return "Price : $" + price + " Size : " + size + " Toppings : " + toppings;
}
}

class SeatedPizzaOrder : PizzaOrder
{
private int tableNo;

public int TableNumber
{
get { return tableNo; }
set { tableNo = value; }
}

private string serverName;

public string ServerName
{
get { return serverName; }
set { serverName = value; }
}

public SeatedPizzaOrder(string topp, int siz, decimal prce,int table, string serverN):base(topp,siz,prce)
{
tableNo = table;
serverName = serverN;
}

public override string ToString()
{
return base.ToString() + " Table Number : " + tableNo + " Server Name : " + serverName;
}
}

class DeliveryPizzaOrder : PizzaOrder
{
private string driverName;

public string DriverName
{
get { return driverName; }
set { driverName = value; }
}

public DeliveryPizzaOrder(string topp, int siz, decimal prce, string driverN) : base(topp, siz, prce)
{
driverName = driverN;
}

public override string ToString()
{
return base.ToString() + " Driver Name : " + driverName;
}
}

class Pizza
{
public static void Main()
{
Console.WriteLine("Enter the details for Seated Pizza Order");
Console.WriteLine("Enter the toppings : ");
string toppings = Console.ReadLine();
Console.WriteLine("Enter the size :");
int size = Int32.Parse(Console.ReadLine());
Console.WriteLine("Enter the Price : ");
decimal price = Decimal.Parse(Console.ReadLine());
Console.WriteLine("Enter the table number : ");
int tbleNo = Int32.Parse(Console.ReadLine());
Console.WriteLine("Enter the Server Name : ");
string serverName = Console.ReadLine();
SeatedPizzaOrder seaterPizzaOrder = new SeatedPizzaOrder(toppings, size, price, tbleNo, serverName);

Console.WriteLine("Enter the details for Delivery Pizza Order");
Console.WriteLine("Enter the delivery person name : ");
string person = Console.ReadLine();
DeliveryPizzaOrder deliveryPizzaOrder = new DeliveryPizzaOrder(toppings, size, price,person);

Console.WriteLine("Details for Seated Pizza Order : ");
Console.WriteLine(seaterPizzaOrder);
Console.WriteLine("Details for Delivery Pizza Order : ");
Console.WriteLine(deliveryPizzaOrder);

}
}

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
using C# language This program will demonstrate inheritance. Your Pizza Shop expands and now handles delivery...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using Java, I created 3 files, Pizza,PizzaOrder, and PizzaOrder_Demo that I attached down below. But I...

    Using Java, I created 3 files, Pizza,PizzaOrder, and PizzaOrder_Demo that I attached down below. But I cannot compile it. Could you please point out the error.The question is that This programming project extends Q1. Create a PizzaOrder class that allows up to three pizzas to be saved in an order. Each pizza saved should be a Pizza object as described in Q1. In addition to appropriate instance variables and constructors, add the following methods: public void setNumPizzas(int numPizzas)—sets the number...

  • C# Programming Exercise and Bonus Exercise (Next Page) 1) Define a class called OrderPizza that has...

    C# Programming Exercise and Bonus Exercise (Next Page) 1) Define a class called OrderPizza that has member variables to track the type of pizza being order (either deep dish, hand tossed, or pan) along with the size (small, medium or large), type of toppings (pepperoni, cheese etc.) and the number of toppings. Create accessors for each property (ex.: type, size, type of toppings, and number of toppings). Implementation class should have a CalculateOrderPayment method to compute the total cost of...

  • Here is a sample run of the tester program: Make sure your program follows the Java...

    Here is a sample run of the tester program: Make sure your program follows the Java Coding Guidelines. Consider the following class: /** * A store superclass with a Name and Sales Tax Rate */ public class Store {      public final double SALES_TAX_RATE = 0.06;      private String name;           /**      * Constructor to create a new store      * @param newName      */      public Store(String newName)      {           name = newName;      }     ...

  • It is a C++ program by using inheritance and vectors My professor said that all the files should be separate. like File.cpp, File.h, Text.cpp,Text.h,Main.cpp I already have these files File.cpp #inclu...

    It is a C++ program by using inheritance and vectors My professor said that all the files should be separate. like File.cpp, File.h, Text.cpp,Text.h,Main.cpp I already have these files File.cpp #include "File.h" // Constructor of File that takes File name and type as arguments File::File(string type, string name) {    this->type = type;    this->name = name; } //returns the type. string File::getType() {    return type; } //returns the name of file. string File::getName() {    return name; } File.h #ifndef __FILE_H__ #define...

  • Design a restaurant class to help manage multiple restaurants and their menus equiremen The class...

    program is C# Design a restaurant class to help manage multiple restaurants and their menus equiremen The class contains: 1) A static int variable named storeCounter that starts at 1 and increments for each new restaurant item that is created 2) A string array called Menu 3) An int variable called StoreID 4) A Boolean variable called isOpen 5) A no-argument constructor that performs the following a. Sets storelD to storeCounter, then increments storeCounter b. Sets isOpen to true c....

  • 1) This exercise is about Inheritance (IS-A) Relationship. A) First, draw the UML diagram for class...

    1) This exercise is about Inheritance (IS-A) Relationship. A) First, draw the UML diagram for class Student and class ComputerSystemsStudent which are described below. Make sure to show all the members (member variables and member functions) of the classes on your UML diagram. Save your UML diagram and also export it as a PNG. B) Second, write a program that contains the following parts. Write each class interface and implementation, in a different .h and .cpp file, respectively. a) Create...

  • 1. Create a class named Pizza with data fields dor desceiption ( such as sasuage and...

    1. Create a class named Pizza with data fields dor desceiption ( such as sasuage and onion) and price. include a constructor fhay requires arguments for borh fields ans a method to diplay the data. Create a subclass names DelicedPizza that inherits from Pizza bit adds a delivery fee and a delicery address. The description, price, and delicery address are required as arguments to the constructor. The delivery fee is $3 if the pizza ordered cost more that $15; otherwise...

  • Purpose Demonstrate the ability to create and use subclasses and inheritance. This includes overriding method behaviors...

    Purpose Demonstrate the ability to create and use subclasses and inheritance. This includes overriding method behaviors and using polymorphism. Assignment Create an Aircraft class that has several properties that are common to all aircraft (Ex: number of engines, seat capacity). You define the name of the Class and the actual fields. The fields MUST BE PRIVATE!!! You must define a constructor that allows you to provide at least some of the field values used for an aircraft. You must define...

  • Inheritance Problem: (C++) (The MyPoint class) Design a class named MyPoint to represent a point with...

    Inheritance Problem: (C++) (The MyPoint class) Design a class named MyPoint to represent a point with x-and y-coordinates. The class contains: Two data fields x and y that represent the coordinates. A no-arg constructor that creates a point (0, 0). A constructor that constructs a point with specified coordinates using passed in arguments. Two get functions for data fields x and y, respectively. A method named distance that returns the distance from this point to another point of the MyPoint...

  • Visual Basic 2015: Extra 18-1 Use inheritance with the Inventory Maintenance Application Source Code: 1. frmNewItem.vb...

    Visual Basic 2015: Extra 18-1 Use inheritance with the Inventory Maintenance Application Source Code: 1. frmNewItem.vb Public Class frmNewItem Public InvItem As InvItem Private Sub frmNewItem_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.LoadComboBox() End Sub Private Sub LoadComboBox() cboSizeOrManufacturer.Items.Clear() If rdoPlant.Checked Then cboSizeOrManufacturer.Items.Add("1 gallon") cboSizeOrManufacturer.Items.Add("5 gallon") cboSizeOrManufacturer.Items.Add("15 gallon") cboSizeOrManufacturer.Items.Add("24-inch box") cboSizeOrManufacturer.Items.Add("36-inch box") Else cboSizeOrManufacturer.Items.Add("Bayer") cboSizeOrManufacturer.Items.Add("Jobe's") cboSizeOrManufacturer.Items.Add("Ortho") cboSizeOrManufacturer.Items.Add("Roundup") cboSizeOrManufacturer.Items.Add("Scotts") End If End Sub Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click If IsValidData() Then InvItem = New InvItem(CInt(txtItemNo.Text),...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT