0% found this document useful (0 votes)
19 views4 pages

Project Fawad

The code defines a Pizza class with properties for size, toppings, and methods to get/set values and calculate cost. It takes user input for a pizza order, creates a Pizza object, displays the order details and calculated cost.

Uploaded by

23-cs-124
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views4 pages

Project Fawad

The code defines a Pizza class with properties for size, toppings, and methods to get/set values and calculate cost. It takes user input for a pizza order, creates a Pizza object, displays the order details and calculated cost.

Uploaded by

23-cs-124
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

OPEN ENDED LAB

OOP

Submitted By:
Fawad Tariq
CS-23-16
“D”

Submitted to:
SIR M.ASIF

Dated:
2/05/24

Department of Computer Science,


HITEC University, Taxila

Create a class named Pizza that stores information about a single pizza. It
should contain the..?

Solution:
Brief description (3-5 lines)
Provided code defines a piza class (should be spelled "Pizza") for creating pizza objects with size, cheese, ham, and
pepperoni toppings. It also includes a main method that allows users to input their pizza preferences and calculates
the total cost. Here's a 3-line summary:
Pizza Class: Defines a Pizza class with properties for size, toppings, and methods to access, calculate cost, and get
description.
User Input: Takes user input for size and number of toppings using Scanner.
Order and Cost: Creates a Pizza object, displays its description, and calculates the total cost.

The code
import java.util.Scanner;
public class piza {
private String size;
private int chesetoppings;
private int hamtoppings;
private int pepporoni;
public piza(String size,int chesetoppings,int hamtoppings,int pepporoni){
this.size = size;
this.chesetoppings = chesetoppings;
this.pepporoni = pepporoni;
this.hamtoppings = hamtoppings;
}
public String getsize(){
return size;
}
public int getchesetoppings(){
return chesetoppings;
}
public int getpepporoni(){
return pepporoni;
}
public int gethamtoppings(){
return hamtoppings;
}
public void setsize(){
this.size = size;
}
public void setchesetoppings(){
this.chesetoppings = chesetoppings;
}
public void setpepporoni(){
this.pepporoni = pepporoni;
}

Page 1 of 4
public void sethamtoppings(){
this.hamtoppings = hamtoppings;
}
public double calcCost() {
double cost;
switch (size.toLowerCase()) {
case "small":
cost = 500 + 20 * (chesetoppings + pepporoni + hamtoppings);
break;
case "medium":
cost = 1200 + 200 * (chesetoppings + pepporoni + hamtoppings);
break;
case "large":
cost = 1400 + 2 * (chesetoppings + pepporoni + hamtoppings);
break;
default:
cost = 0;
}
return cost;
}
public String getDescription() {
return "Pizza size: " + size + ", Cheese toppings: " + chesetoppings +
", Pepperoni toppings: " + pepporoni + ", Ham toppings: " + hamtoppings;
}
public static void main(String []args){
Scanner scanner = new Scanner(System.in);
System.out.println("pizza size");
System.out.println("small,medium,large:");
String size = scanner.nextLine();
System.out.println("pizza chese toppings:");
int chesetoppings = scanner.nextInt();
System.out.println("pizza peporoni toppings:");
int pepporoni = scanner.nextInt();
System.out.println("pizza hamtoppings:");
int hamtoppings = scanner.nextInt();
piza ob1 = new piza (size, chesetoppings, hamtoppings, pepporoni);
System.out.println("pizza menu:");
System.out.println(ob1.getDescription());
System.out.println("Total cost : pkr " + ob1.calcCost());
scanner.close();
}
}
The results (Screenshot)

Page 2 of 4
Conclusion: This program creates a user-interactive pizza ordering system. Users can specify
the size and number of toppings for their pizza. The program then calculates the total cost
based on the chosen size and a flat rate per topping. It displays the pizza description and final
cost.

23-CS-016

Page 3 of 4

You might also like