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

Class and Object Programs-Past Papers

Uploaded by

poojadimpal9
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Class and Object Programs-Past Papers

Uploaded by

poojadimpal9
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Class and Object Programs

1. Define a class Student as given below:


Data members/instance variables:
name, age, m1, m2, m3 (marks in 3 subjects), maximum, average

Member methods:

1. A parameterized constructor to initialize the data members.


2. To accept the details of a student.
3. To compute the average and the maximum out of three marks.
4. 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.

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


Data Members Purpose
int bno To store the bike number
int phno To store the phone number of the customer
String name To store the name of the customer
int days To store the number of days the bike is taken
on rent
int charge To calculate and store the rental charge

Member Methods Purpose


void input() To input and store the details of the customer
void compute() To compute the rental charge
void display() To display the details in the given 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 xxxxxxxx xxxx xxx xxxxxx
3. Define a class called Library with the following description:
Instance Variables/Data Members:
int accNum — stores the accession number of the book.
String title — stores the title of the book.
String author — stores the name of the author.
Member methods:

1. void input() — To input and store the accession number, title and author.
2. void compute() — To accept the number of days late, calculate and
display the fine charged at the rate of Rs. 2 per day.
3. 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 named FruitJuice with the following description:

Data Members Purpose


int product_code stores the product code number
String flavour stores the flavour of the juice (e.g., orange,
apple, etc.)
String pack_type stores the type of packaging (e.g., tera-pack,
PET bottle, etc.)
int pack_size stores package size (e.g., 200 mL, 400 mL, etc.)
int product_price stores the price of the product

Member Methods Purpose


FruitJuice() constructor to initialize integer data members to 0
and string data members to ""
void input() to input and store the product code, flavour, pack
type, pack size and product price
void discount() to reduce the product price by 10
void display() to display the product code, flavour, pack type,
pack size and product price

5. Define a class named movieMagic with the following description:


Data Members Purpose
int year To store the year of release of a movie
String title To store the title of the movie
float rating To store the popularity rating of the movie
(minimum rating=0.0 and maximum
rating=5.0)
Member Methods Purpose
movieMagic() Default constructor to initialize numeric data
members to 0 and String data member to "".
void accept() To input and store year, title and rating
void display() To display the title of the movie and a
message based on the rating as per the table
given below

Rating Message to be displayed


0.0 to 2.0 Flop
2.1 to 3.4 Semi-Hit
3.5 to 4.4 Hit
4.5 to 5.0 Super-Hit
Write a main method to create an object of the class and call the above
member methods.

6. Define a class called ParkingLot with the following description:

Instance variables/data members:


int vno — To store the vehicle number.
int hours — To store the number of hours the vehicle is parked in the parking
lot.
double bill — To store the bill amount.

Member Methods:
void input() — To input and store the vno and hours.
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.
void display() — To display the detail.

Write a main() method to create an object of the class and call the above
methods.

7. Define a class named BookFair with the following description:

Instance variables/Data members:


String Bname — stores the name of the book
double price — stores the price of the book

Member methods:
(i) BookFair() — Default constructor to initialize data members
(ii) void Input() — To input and store the name and the price of the book.
(iii) 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 10% of price
equal to ₹3000
More than ₹3000 15% of 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.

8. Define a class ElectricBill with the following specifications:

class : ElectricBill

Instance variables / data member:


String n — to store the name of the customer
int units — to store the number of units consumed
double bill — to store the amount to be paid

Member methods:
void accept( ) — to accept the name of the customer and number of units
consumed
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.

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


Name of the customer: ………………………
Number of units consumed: ………………………
Bill amount: ………………………

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

9. Design a class RailwayTicket with following description:

Instance variables/data members:


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

Member methods:
void accept() — To take input for name, coach, mobile number and amount.
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
void display() — To display all details of a customer such as name, coach, total
amount and mobile number.

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

10.Design a class name ShowRoom with the following description:

Instance variables / Data members:


String name — To store the name of the customer
long mobno — To store the mobile number of the customer
double cost — To store the cost of the items purchased
double dis — To store the discount amount
double amount — To store the amount to be paid after discount

Member methods:
ShowRoom() — default constructor to initialize data members
void input() — To input customer name, mobile number, cost
void calculate() — To calculate discount on the cost of purchased items,
based on following criteria

Cost Discount (in


percentage)
Less than or equal to ₹10000 5%
More than ₹10000 and less than or equal to 10%
₹20000
More than ₹20000 and less than or equal to 15%
₹35000
More than ₹35000 20%

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.
11.Design a class with the following specifications:

Class name: Student

Member variables:
name — name of student
age — age of student
mks — marks obtained
stream — stream allocated

(Declare the variables using appropriate data types)

Member methods:
void accept() — Accept name, age and marks using methods of Scanner class.
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
void print() – Display student name, age, mks and stream allocated.

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

12.Define a class called with the following specifications:

Class name: Eshop

Member variables:
String name: name of the item purchased
double price: Price of the item purchased

Member methods:
void accept(): Accept the name and the price of the item using the methods of
Scanner class.
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 %

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.

You might also like