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

OOPs Practice

Uploaded by

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

OOPs Practice

Uploaded by

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

OOPs Practice

24 August 2024 15:24

• Create a class Movie with attributes title, genre, and rating. Implement a method
isFamilyFriendly() that returns true if the rating is below 13, otherwise returns false. Create an
object of the Movie class, and test the isFamilyFriendly() method with different movie ratings.

• Create a class BankCustomer with private attributes customerName and accountBalance.


Provide a method deposit(double amount) to add money to the balance and another method
withdraw(double amount) to subtract money, ensuring the balance doesn't go negative. Create
an object of the BankCustomer class, perform some transactions, and display the final balance.

• Create a class Polygon with a method numberOfSides(). Then, create two subclasses Triangle
and Square that extend Polygon. Each subclass should override the numberOfSides() method to
return the correct number of sides. Demonstrate polymorphism by creating an array of Polygon
objects that includes instances of Triangle and Square, and print the number of sides for each.

• Create a class StudentRecord with attributes name, rollNumber, and marks[] (an array of marks
in different subjects). Implement methods calculateTotalMarks() and calculateAverageMarks().
Create an object of the StudentRecord class, and display the total and average marks of a
student.

• Create an abstract class Account with attributes accountNumber and balance, and an abstract
method calculateInterest(). Create two subclasses SavingsAccount and CurrentAccount, each
implementing calculateInterest() based on their specific rules. Instantiate both subclasses and
display the interest calculated.

• Create an interface Playable with a method play(). Then, create two classes Football and Cricket
that implement the Playable interface. Write a method startGame(Playable game) that calls the
play() method. Test this method with both Football and Cricket objects.

• Create a class Employee with attributes name and salary. Add a method giveRaise(double
percentage) that increases the employee's salary by the given percentage. Demonstrate
method overloading by adding another version of giveRaise() that takes a flat amount instead
of a percentage. Test both versions with an Employee object.

• Create a class BookStore with an attribute inventory (a list of books). Implement methods
addBook(String bookName), removeBook(String bookName), and searchBook(String
bookName) that allow you to manage the bookstore's inventory. Create a BookStore object and
test these methods by adding, removing, and searching for books in the inventory.

• Create a class Smartphone with attributes brand, model, and batteryLife. Implement a method
useBattery(int hours) that decreases the battery life by a specified number of hours. Ensure the
battery life does not drop below zero. Create an object of the Smartphone class, simulate some
usage, and display the remaining battery life.

• Create a class Library with attributes libraryName and books (a list of books). Add a method
listAvailableBooks() that prints all books in the library. Create a method borrowBook(String
bookName) that allows a user to borrow a book by removing it from the list of available books.
Create a Library object and demonstrate borrowing a book and listing the available books.

New Section 1 Page 1

You might also like