Programming Exercise and Bonus Exercise (Next Page) 1) Define a class called Ord
ID: 3901279 • Letter: P
Question
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 the pizza order and return it as a double according to the rules: Small pizza S10+ S2 per topping Medium pizza $14+ S2 per topping Large pizza S17 +S2 per topping Also a PrintReceipt method to display the order information with the total amount to pay. Write a OrderPizzaTest class to demonstrate that your program is working. IMPORTANT: remember to initialize the constructor (example: if we use the given default values for the example below the total amount to pay is $23: OrderPizza myPizzaOrder = new OrderPizza("deep dish","large", "cheese", 3); ). Lastly, prompt the user to enter a new order with different values (hint: use the Console.ReadLine0 method to obtain user input) and redisplay the output with the new information. /CLASS IMPLEMENTATION BEGINS HERE public class OrderPizzaExplanation / Answer
OrderPizza.java
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class OrderPizza
{
String Type;
String Size;
String Topping;
int ToppingQuantity;
double Price;
private double Calculate(String Size, int ToppingQuantity)
{
double price = 0;
if(Size.equals("Small"))
{
price = 10;
}
else if(Size.equals("Medium"))
{
price = 14;
}
else if(Size.equals("Large"))
{
price = 17;
}
return (price + (2*ToppingQuantity));
}
public OrderPizza(String Type,String Size, String Topping, int ToppingQuantity)
{
this.Type = Type;
this.Size = Size;
this.Topping = Topping;
this.ToppingQuantity = ToppingQuantity;
this.Price = this.Calculate(Size,ToppingQuantity);
}
private String getType()
{
return this.Type;
}
private String getSize()
{
return this.Size;
}
private String getTopping()
{
return this.Topping;
}
private int getToppingQuantity()
{
return this.ToppingQuantity;
}
private double getPrice()
{
return this.Price;
}
public void PrintReciept()
{
System.out.println(" ");
System.out.println("=======================================");
System.out.println(" Order Information");
System.out.println("---------------------------------------");
System.out.println(" Type: "+this.getType());
System.out.println(" Size: "+this.getSize());
System.out.println(" Topping: "+this.getTopping());
System.out.println(" Topping Quantity: "+this.getToppingQuantity());
System.out.println("---------------------------------------");
System.out.println(" Price: $"+this.getPrice());
System.out.println("=======================================");
}
public static void main(String[] args)
{
try
{
String Type="",Size="",Topping="";
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(" Pizza Type ");
System.out.println(" --------------");
System.out.println(" 1. Deep Dish");
System.out.println(" 2. Hand Tossed");
System.out.println(" 3. Pan");
System.out.print(" > Your Option : ");
int optionForType = Integer.parseInt(br.readLine());
switch(optionForType)
{
case 1 : Type="Deep Dish"; break;
case 2 : Type="Hand Tossed"; break;
case 3 : Type="Pan"; break;
default: Type="Default"; break;
}
System.out.println(" Size Type ");
System.out.println(" --------------");
System.out.println(" 1. Small");
System.out.println(" 2. Medium");
System.out.println(" 3. Large");
System.out.print(" > Your Option : ");
int optionForSize = Integer.parseInt(br.readLine());
switch(optionForSize)
{
case 1 : Size="Small"; break;
case 2 : Size="Medium"; break;
case 3 : Size="Large"; break;
default: Size="Default"; break;
}
System.out.println(" Topping Type ");
System.out.println(" --------------");
System.out.println(" 1. Pepperoni");
System.out.println(" 2. Cheese");
System.out.println(" 3. Onion");
System.out.println(" 4. Chicken");
System.out.print(" > Your Option : ");
int optionForTopping = Integer.parseInt(br.readLine());
switch(optionForTopping)
{
case 1 : Topping="Pepperoni"; break;
case 2 : Topping="Cheese"; break;
case 3 : Topping="Onion"; break;
case 4 : Topping="Chicken"; break;
default: Topping="Default"; break;
}
System.out.print(" > Tooping Quantity : ");
int ToppingQuantity = Integer.parseInt(br.readLine());
OrderPizza OP = new OrderPizza(Type, Size, Topping, ToppingQuantity);
OP.PrintReciept();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
DisplayTableValues.java
public class DisplayTableValues
{
public static void main(String[] args)
{
System.out.println("N 10*N 100*N 1000*N");
int i=1;
while(i<=10)
{
System.out.println((i)+" "+(10*i)+" "+(100*i)+" "+(1000*i));
i++;
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.