Question

In: Computer Science

You are asked to implement a class Pizza, the default values of properties are given as:...

You are asked to implement a class Pizza, the default values of properties are given as:


Diameter: 8.0

Name: DefaultName

Supplier: DefaultSupplier



Hints: A pizza with diameter greater than 15 will be considered as a large pizza. The method IsLargePizza will return a true if the pizza is considered as a large pizza or a false if it is not considered as a large pizza. There are two ToString methods, the one with no parameter passed will return the information contains name, supplier and whether it is a large pizza or not. The other ToString method takes bestBefore information and will append it to the information returned by the ToString() method.


The typical output for ToString() method:

DefaultName is a large pizza supplied by DefaultSupplier.


The typical output for ToString(string bestBefore) method:

DefaultName is a large pizza supplied by DefaultSupplier. It is best before bestBeforeInformation.


Please noted that for each blank space, you may need to put more than one statement.


using System;

using System.Collections.Generic;

using System.Text;


namespace ConsoleApp4

{

public class Pizza

{

public double Diameter

{

get;

set;

}


public string Name

{

get;

set;

}


public string Supplier

{

get;

set;

}


public Pizza()

{

1.___________

}




public Pizza(double diameter, string name, string supplier)

{

2.___________

}


public bool IsLargePizza()

{

3.___________

}


4._______ string ToString()

{

5.___________

}


6._______ ToString(string bestBefore)

{

7.___________

}

}

}

Solutions

Expert Solution

using System;

using System.Collections.Generic;

using System.Text;


namespace ConsoleApp4

{

public class Pizza

{

public double Diameter

{

get;

set;

}


public string Name

{

get;

set;

}


public string Supplier

{

get;

set;

}


public Pizza()

{

Diameter = 10;
Name = "DefaultName";
Supplier = "DefaultSupplier";


}


public Pizza(double diameter, string name, string supplier)

{

Diameter = diameter;
Name = name;
Supplier = supplier;

}


public bool IsLargePizza()

{

if(Diameter > 15)
return true;
else
return false;

}


public override string ToString()

{

return Name +" is a large pizza supplied by "+ Supplier +".";

}


public string ToString(string bestBefore)

{

return Name +" is a large pizza supplied by "+ Supplier+". It is best before "+ bestBefore+".";

}

}

}


public class Test
{
   public static void Main()
   {
       Pizza p = new Pizza();
       p.Name = "Margherita";
       p.Diameter = 16;
       p.Supplier = "Dominos";
      
      
       Console.WriteLine(p.ToString());
      
       Console.WriteLine(p.ToString("six hours after delivery"));
      
       Console.WriteLine("It is large Pizza : "+p.IsLargePizza());
   }
}

Output:

Margherita is a large pizza supplied by Dominos.
Margherita is a large pizza supplied by Dominos. It is best before six hours after delivery.
It is large Pizza : True

Do ask if any doubt.


Related Solutions

When you create a C++ class, you are given 4 default methods. What are they and...
When you create a C++ class, you are given 4 default methods. What are they and why is it important that you remember that these exist?
you are asked to implement a C++ class to model a sorted array of unsigned integers....
you are asked to implement a C++ class to model a sorted array of unsigned integers. The class is to be used in an embedded application that cannot assume the presence of the STL. The array has to be dynamically allocated in such a way that allows programmers using it to specify the required size. Class will provide (1) provide the appropriate constructors and destructor; (2) provide methods for updating, and showing numbers in/to the array (e.g., to be used...
c++ programming 1.1 Class definition Define a class bankAccount to implement the basic properties of a...
c++ programming 1.1 Class definition Define a class bankAccount to implement the basic properties of a bank account. An object of this class should store the following data:  Account holder’s name (string)  Account number (int)  Account type (string, check/savings/business)  Balance (double)  Interest rate (double) – store interest rate as a decimal number.  Add appropriate member functions to manipulate an object. Use a static member in the class to automatically assign account numbers. 1.2 Implement...
In C++, define the class bankAccount to implement the basic properties of a bank account. An...
In C++, define the class bankAccount to implement the basic properties of a bank account. An object of this class should store the following data: Account holder’s name (string), account number (int), account type (string, checking/saving), balance (double), and interest rate (double). (Store interest rate as a decimal number.) Add appropriate member functions to manipulate an object. Use a static member in the class to automatically assign account numbers. Also declare an array of 10 components of type bankAccount to...
Write the definition of a class, swimmingPool, to implement the properties of a swimming pool. Your...
Write the definition of a class, swimmingPool, to implement the properties of a swimming pool. Your class should have the instance variables to store the length (in feet), width (in feet), depth (in feet), the rate (in gallons per minute) at which the water is filling the pool, and the rate (in gallons per minute) at which the water is draining from the pool. Add appropriate constructors to initialize the instance variables. Also, add member functions to do the following:...
1. You are given Stack.java, an interface class for Stacks. /* Use an array to implement...
1. You are given Stack.java, an interface class for Stacks. /* Use an array to implement the Stack.java in a class called ArrayStack.java that uses Generics. Write a main function that creates two stacks, one containing 10 Integers and a different one containing 10 Strings, and reverses there contents using a method called reverse that takes as a paramater a Generic array. You will need to implement all the methods of Stack.java as well as create a toString method in...
You are given four values (1.073, 4.153, 1.08, and 4.6) and asked to conduct calculations on...
You are given four values (1.073, 4.153, 1.08, and 4.6) and asked to conduct calculations on them. You perform a series of mathematical operations using the values and make a table that includes the calculated value as displayed on your calculator: Mathematical operation Value displayed by calculator 1.073+4.153+1.08+4.6 10.9060 1.073×1.08 1.15884 4.153−1.08 3.07300 4.153/31.0341 0.133821 4.6/31.0341 0.148224 Round each of the values displayed by the calculator to the correct number of significant figures, and place the value in the bin...
Given the following UML class diagram, implement the class as described by the model. Use your...
Given the following UML class diagram, implement the class as described by the model. Use your best judgment when implementing the code inside of each method. +---------------------------------------------------+ | Polygon | +---------------------------------------------------+ | - side_count : int = 3 | | - side_length : double = 1.0 | +---------------------------------------------------+ | + Polygon() | | + Polygon(side_count : int) | | + Polygon(side_count : int, side_length : double) | | + getSides() : int | | + setSides(side_count : int) | |...
Given: You are given a Python Class template. In this class there is a class variable...
Given: You are given a Python Class template. In this class there is a class variable vector, is a list of N non-negative integers and are stored (in positions 0, 1, 2, ... (N-1)), where at least one integer is 0. Task: Write a recursive function "findAllPaths" to find all possible path through V starting at position 0, and ending at the location of 0, in accordance with the Rule below. If no such path exists, "paths" should be an...
Java Implement a class named “Fraction” with the following properties: numerator: int type, private denominator: int...
Java Implement a class named “Fraction” with the following properties: numerator: int type, private denominator: int type, private and the following methods: one default constructor which will create a fraction of 1/1. one constructor that takes two parameters which will set the values of numerator and denominator to the specified parameters. int getNum() : retrieves the value of numerator int getDenom(): retrieves the value of the denominator Fraction add(Fraction frac): adds with another Fraction number and returns the result in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT