Вы находитесь на странице: 1из 5

Assignment

Department of CSIT
Due - 29th Mar 2020, 11.55 PM
Max Marks – 30 (Weightage out of 100 is 20%)
Policy: Solve the programs as per instructions given in each question. Use the basic template with
comments is being shown by the instructor in each problem definition. Export the project in archive
format before submitting.

Problem. Write a program that computes the cost of choosing a pizza using Object Oriented
Programming. Must use the template given below. [30 Marks]
import java.util.ArrayList;

// Change the class type if required. [1 Mark]

public abstract class Pizza {

private static final double costOfTopping = 2.5;

// Price of Small, medium and large pizza is 10$, 12$ and 14$ respectively.

private double[] PriceOfBasePizza = {10.00, 12.00, 14.00};


private double TotalCost;
private String type;

protected ArrayList<String> toppings = new ArrayList<String>();


private String size;

//Initialize the default constructor for this class. [1 Mark]

public Pizza(String type, String size) {

this.type = type;
this.size = size;
}

/* Generate Setters and getters for the variables which you will be
requiring later [3 Marks] */

public abstract void getToppings();

//Override the toString() method here. [2 Marks]

public interface PizzaPrice {

public double PriceofSmallPizza(double BasePriceSmall);


public double PriceofMediumPizza(double BasePriceMedium);
public double PriceofLargePizza(double BasePriceLarge);
public double TaxOnPizza(double TotalCost);

}
// Change, if required with inheritance and interface. [Inherit pizza and
implement the interface] [2 Marks]

public class Regular {

public Regular(String type, String size) {


super(type, size);
// TODO Auto-generated constructor stub
}

/*Define the toppings here, ask the user, max 2 toppings allowed for Regular type
pizza. Populate your ArrayList of Toppings defined in Pizza class in here. Also
compute here the total cost of ordering the extra toppings. [3 Marks] */

@Override
public void getToppings() {

Scanner in = new Scanner(System.in);


System.out.println("How many toppings would you like?");
int numToppings = in.nextInt();

/*Implement the PizzaPrice Interface’s methods here to find the price of each
pizza by its size using the cost of toppings. One of the method is implemented for
your reference. [3 Marks] */

@Override
public double PriceofSmallPizza(double costTopping) {
// TODO Auto-generated method stub
return costTopping+this.getPriceOfBasePizza ()[0];
}

}
// Change, if required with inheritance and interface. [Inherit pizza and
implement the interface] [2 Marks]

public class Feast {

public Feast(String type, String size) {


super(type, size);
// TODO Auto-generated constructor stub
}

/*Define the toppings here, ask the user, max 3 toppings allowed for Feast type
pizza. Populate your ArrayList of Toppings defined in Pizza class in here. Also
compute here the total cost of ordering the extra toppings. [3 Marks] */

@Override
public void getToppings() {

Scanner in = new Scanner(System.in);


System.out.println("How many toppings would you like?");
int numToppings = in.nextInt();

/*Implement the PizzaPrice Interface’s methods here to find the price of each
pizza by its size using the cost of toppings. One of the method is implemented for
your reference. [3 Marks] */

@Override
public double PriceofSmallPizza(double costTopping) {
// TODO Auto-generated method stub
return costTopping+this.getPriceOfBasePizza ()[0];
}

}
import java.util.Scanner;

public class PizzaShop {

public static void main(String[] args) {

// ask for customer name, type and size of pizza.

Scanner in = new Scanner(System.in);


System.out.println("Enter customer name: ");
String name = in.nextLine();
System.out.println("What type of pizza would you like, regular or feast
");
String type = in.nextLine();

System.out.println("What size of pizza would you like, small, medium or


large? ");
String size = in.nextLine();

/* Find total price of pizza as per selection of the user for each pizza type.
[5 Marks] */

if (type.equalsIgnoreCase("regular")){

}
if(type.equalsIgnoreCase()){

/* Finally call the toString() method from your Pizza Class and modify it to
display the customer name, their type, size and toppings and the total cost of the
pizza. [2 Marks] */

Вам также может понравиться