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?
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...
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...
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...
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...
32-34.) You are asked to value a credit default swap on a bond with a $1,000,000...
32-34.) You are asked to value a credit default swap on a bond with a $1,000,000 face value. In the event of default, the bond is expected to have a recovery rate of 60%. The probability of default is 10%. You will be purchasing 3 years of protection. The Treasury STRIP rates are as follows: Maturity STRIP Rate 1 4% 2 6% 3 8% What is the cost of the credit default swap?
In this homework you will implement a Library class that uses your Book and Person class...
In this homework you will implement a Library class that uses your Book and Person class from homework 2, with slight modifications. The Library class will keep track of people with membership and the books that they have checked out. Book.java You will need to modify your Book.java from homework 2 in the following ways: field: dueDate (private)             A String containing the date book is due.  Dates are given in the format "DD MM YYYY", such as "01 02 2017"...
Given the following program with fill in the blanks, implement the PQ class which is priority...
Given the following program with fill in the blanks, implement the PQ class which is priority Queue MAX heap; the higher the number, the higher the prority of that number. None of the public methods has been implemented. You will need to write other methods to help implement some of the methods. For example you will need to implement bubbleUp to help with the insert method. Methods to implement: insert -> insert one element into the PQ and maintain heap...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT