0% found this document useful (0 votes)
5 views

Constructor Based Programs

Uploaded by

Soniya Babu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Constructor Based Programs

Uploaded by

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

Create a class named Pizza that stores details about a pizza.

It should contain the following:

Instance Variables:
String pizzaSize — to store the size of the pizza (small, medium, or large)
int cheese — the number of cheese toppings
int pepperoni — the number of pepperoni toppings
int mushroom — the number of mushroom toppings

Member Methods:
Constructor — to initialise all the instance variables
CalculateCost() — A public method that returns a double value, that is, the cost of the pizza.
Pizza cost is calculated as follows:

Small: Rs.500 + Rs.25 per topping

Medium: Rs.650 + Rs.25 per topping

Large: Rs.800 + Rs.25 per topping

PizzaDescription() — A public method that returns a String containing the pizza size, quantity of each
topping, and the pizza cost as calculated by CalculateCost()

Define a Class Electricity described as follows:

Data members:

Name, Consumer Number, Units consumed.

Member methods

Electricity (name,cno,unit)

ii)compute() - units consumed according to the conditions given below

upto 100 units:80 paise per unit

for next 100 units:Re.1 per unit

for more than 200 units: Rs.1.25 per unit

To display disp() the details including name & consumer number.

Write a main method to create object of a class & call the above member method

You might also like