0% found this document useful (0 votes)
14 views15 pages

Ch#11 Constructors

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)
14 views15 pages

Ch#11 Constructors

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/ 15

COMPUTER APPLICATIONS

ICSE BOARD PROGRAMS (2010-2024)


Ch#11 CONSTRUCTORS

NAME: CLASS: X SECTION: ROLL NO:

I. Default /Non Parameterized Constructor

1. Define a class named FruitJuice with the following


description: [ICSE -2013]

Data Members/
Purpose
Instance Variables

int product code stores the product code number

stores the flavour of the juice (e.g.,


String flavour
orange, apple, etc.)

stores the type of packaging (e.g.,


String pack type
tera-pack, PET bottle, etc.)

stores package size (e.g., 200 mL,


int pack size
400 mL, etc.)

int product_price stores the price of the product

Pg.1
Member Methods/
Purpose
Member Functions

constructor to initialize integer data


FruitJuice() members to 0 and string data
members to ""

to input and store the product code,


void input() flavour, pack type, pack size and
product price

void discount() to reduce the product price by 10

to display the product code, flavour,


void display() pack type, pack size and product
price

Write a main method to create an object of the class and call


the above member methods.

Pg.2
2. Define a class named MovieMagic with the following
description: [ICSE -2014]

Data Members/ Instance


Purpose
Variables

To store the year of release of a


int year
movie

String title To store the title of the movie

To store the popularity rating of


the movie
float rating
(minimum rating=0.0 and
maximum rating=5.0)

Member Methods/
Purpose
Member Functions

Default constructor to initialize


movieMagic() numeric data members to 0 and
String data member to "".

To input and store year, title and


void accept()
rating

To display the title of the movie


void display() and a message based on the rating
as per the table given below

Rating Message to be displayed

Pg.3
Rating Message to be displayed

0.0 to 2.0 Flop

0.0 to 2.0 Flop

2.1 to 3.4 Semi-Hit

3.5 to 4.4 Hit

Pg.4
Rating Message to be displayed

0.0 to 2.0 Flop

4.5 to 5.0 Super-Hit

Write a main method to create an object of the class and call


the above member methods.

3. Define a class named BookFair with the following


description: [ICSE -2016]

Instance variables/Data members:

(a) String Bname — stores the name of the book


(b) double price — stores the price of the book

Member methods /Member Functions:

(a) BookFair() — Default constructor to initialize data members


(b) void Input() — To input and store the name and the price of
the book.
(c) void calculate() — To calculate the price after discount.
Discount is calculated based on the following criteria.

Price Discount

Less than or equal to ₹1000 2% of price

More than ₹1000 and less than or equal 10% of


to ₹3000 price

Pg.5
Price Discount

15% of
More than ₹3000
price

(iv) void display() — To display the name and price of the book
after discount.

Write a main method to create an object of the class and call


the above member methods.

4. Design a class name Show Room with the following


description: [ICSE -2019]

Instance variables / Data members:


(a) String name — To store the name of the customer
(b) long mobno — To store the mobile number of the customer
(c) double cost — To store the cost of the items purchase
(d) double dis — To store the discount amount
(e) double amount — To store the amount to be paid after
discount
Member methods / Member Functions:
(a) Show Room() — default constructor to initialize data
members
(b) void input() — To input customer name, mobile number,
cost
(c) void calculate() — To calculate discount on the cost of
purchased items, based on following criteria

Discount (in
Cost
percentage)

Less than or equal to ₹10000 5%

Pg.6
Discount (in
Cost
percentage)

More than ₹10000 and less than or


10%
equal to ₹20000

More than ₹20000 and less than or


15%
equal to ₹35000

More than ₹35000 20%

(d) void display() — To display customer name, mobile number,


amount to be paid after discount.

Write a main method to create an object of the class and call


the above member methods.

II. Non Default Constructor

1. Shasha Travels Pvt. Ltd. gives the following discount to its


customers: [ICSE -2010]

Ticket Amount Discount

Above Rs. 70000 18%

Rs. 55001 to Rs. 70000 16%

Rs. 35001 to Rs. 55000 12%

Rs. 25001 to Rs. 35000 10%

Pg.7
Ticket Amount Discount

Less than Rs. 25001 2%

Write a program to input the name and ticket amount for the
customer and calculate the discount amount and net amount to be
paid.

Display the output in the following format for each customer:

Sl. No. Name Ticket Charges Discount Net Amount

(Assume that there are 15 customers, first customer is given the


serial no (SI. No.) 1, next customer 2 …….. and so on)

2. Define a class called 'Mobike' with the following


specifications: [ICSE -2011]

Data Members/ Instance


Purpose
Variables

int bno To store the bike number

To store the phone number of the


int phno
customer

String name To store the name of the customer

To store the number of days the


int days
bike is taken on rent

int charge To calculate and store the rental


charge

Pg.8
Member Methods/
Purpose
Member Functions

To input and store the details of


void input()
the customer

void compute() To compute the rental charge

To display the details in the given


void display()
format

The rent for a mobike is charged on the following basis:

Days Charge

For first five days ₹500 per day

For next five days ₹400 per day

Rest of the days ₹200 per day

Output:

Bike No. Phone No. Name No. of days Charge

xxxxxxx xxxxxx xxxx xxx xxxx

3. Define a class called Library with the following


description: [ICSE – 2012]

Pg.9
Instance Variables/Data Members:
(a) int accNum — stores the accession number of the book.
(b) String title — stores the title of the book.
(c) String author — stores the name of the author.

Member methods /Member Functions:

(a) void input() — To input and store the accession number, title
and author.
(b) void compute() — To accept the number of days late,
calculate and display the fine charged at the rate of Rs. 2 per
day.
(c) void display() — To display the details in the following
format:
Accession Number Title Author

Write a main method to create an object of the class and call


the above member methods.

4. Define a class called Parking Lot with the following


description: [ICSE – 2015]
Instance variables/data members:
(a) int vno — To store the vehicle number.
(b) int hours — To store the number of hours the vehicle is
parked in the parking lot.
(c) double bill — To store the bill amount.
Member Methods /Member Functions:
(a) void input() — To input and store the vno and hours.
(b) void calculate() — To compute the parking charge at the rate
of ₹3 for the first hour or part thereof, and ₹1.50 for each
additional hour or part thereof.

Pg.10
(c) void display() — To display the detail.
Write a main() method to create an object of the class and call
the above methods.

5. Define a class ElectricBill with the following specifications:


[ICSE – 2017]

Instance variables / Data members:

(a) String n — to store the name of the customer


(b) int units — to store the number of unit’s consumer
(c) double bill — to store the amount to be paid

Member methods /Member Functions:

(a) void accept( ) — to accept the name of the customer and


number of units consumed
(b) void calculate( ) — to calculate the bill as per the following
tariff:

Number of units Rate per unit

First 100 units Rs.2.00

Next 200 units Rs.3.00

Above 300 units Rs.5.00

A surcharge of 2.5% charged if the number of units consumed is


above 300 units.

(c) void print( ) — To print the details as follows:

Name of the customer: ………………………


Number of units consumed: ………………………
Bill amount: ………………………
Pg.11
Write a main method to create an object of the class and call
the above member methods.

6. Design a class RailwayTicket with following description:


[ICSE – 2018]

Instance variables/data members:

(a) String name — To store the name of the customer


(b) String coach — To store the type of coach customer wants to
travel
(c) long mobno — To store customer’s mobile number
(d) int amt — To store basic amount of ticket
(e) int totalamt — To store the amount to be paid after updating
the original amount

Member methods / Member Functions:

(a) void accept() — To take input for name, coach, mobile


number and amount.
(b) void update() — To update the amount as per the coach
selected (extra amount to be added in the amount as follows)

Type of Coaches Amount

First_AC 700

Second_AC 500

Third_AC 250

sleeper None

(c) void display() — To display all details of a customer such as


name, coach, total amount and mobile number.

Pg.12
Write a main method to create an object of the class and call
the above member methods.

7. Design a class with the following specifications:


[ICSE – 2018]

Class name: Student

Member variables /Data members:

(a) name — name of student


(b) age — age of student
(c) mks — marks obtained
(d) stream — stream allocated

(Declare the variables using appropriate data types)

Member methods /Member Functions:

(a) void accept() — Accept name, age and marks using methods
of Scanner class.
(b) void allocation() — Allocate the stream as per following
criteria:

mks stream

>= 300 Science and Computer

>= 200 and < 300 Commerce and Computer

>= 75 and < 200 Arts and Animation

< 75 Try Again

(c) void print() – Display student name, age, mks and stream
allocated.

Pg.13
Call all the above methods in main method using an object.

8. Define a class called with the following specifications:


(Specimen Paper – 2024)

Class name: Eshop

Member variables / Data Members:

(a) String name: name of the item purchased


(b) double price: Price of the item purchased

Member methods /Member Functions:

(a) void accept(): Accept the name and the price of the item
using the methods of Scanner class.

(b) void calculate(): To calculate the net amount to be paid by a


customer, based on the following criteria:

Price Discount

1000 – 25000 5.0%

25001 – 57000 7.5 %

57001 – 100000 10.0%

More than 100000 15.0 %

(c) void display(): To display the name of the item and the net
amount to be paid.

Write the main method to create an object and call the above
methods.
III. Parameterized Constructor

Pg.14
1. Define a class Student as given below:[ICSE – 2010]
Data members/Instance variables:
name, age, m1, m2, m3 (marks in 3 subjects), maximum, average
Member methods /Member Functions:

(a) A parameterized constructor to initialize the data members.


(b) To accept the details of a student.
(c) To compute the average and the maximum out of three
marks.
(d) To display the name, age, marks in three subjects, maximum
and average.
Write a main method to create an object of a class and call the
above member methods.

********************ALL THE BEST


********************

Pg.15

You might also like