0% found this document useful (0 votes)
38 views9 pages

Java OOP Practice Problems

The document outlines various object-oriented programming (OOP) practice problems in Java, including systems for managing libraries, laptops, student enrollments, travel agencies, and hospital appointments. Each system includes class definitions, tasks to be accomplished, input and output formats, and sample test cases. The problems focus on data management and retrieval using lists and classes, emphasizing the application of OOP principles.
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)
38 views9 pages

Java OOP Practice Problems

The document outlines various object-oriented programming (OOP) practice problems in Java, including systems for managing libraries, laptops, student enrollments, travel agencies, and hospital appointments. Each system includes class definitions, tasks to be accomplished, input and output formats, and sample test cases. The problems focus on data management and retrieval using lists and classes, emphasizing the application of OOP principles.
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

Java OOP Practice Problems

📚 Library Management System


Design a system to manage books in multiple libraries.

📦 Classes:
 Class: Book (bookId: int, title: String, author: String, price: double, pages: int)
 Class: Library (libraryId: int, libraryName: String, books: List<Book>)

🎯 Tasks:
1. Find books with page count greater than X.
2. Calculate average price of books in a library.
3. Find the library with the highest number of books.

🔤 Input Format:
First line: Integer n (number of libraries)
For each library:
Library ID, Library Name, Number of books
For each book: Book ID, Title, Author, Price, Pages
Last line: An integer X for page count filter

📤 Output Format:
List of books with pages > X
Average book price of each library
Library with highest number of books

🧪 Sample Test Cases:


4. Test Case 1

Input:
2
101
CityLibrary
2
201
Java101
JohnDoe
500.0
300
202
Python
Alice
600.0
350
102
TownLibrary
1
203
C++
Bob
450.0
280
320

Output:
Books with pages > 320:
202 Python
Average book price:
CityLibrary: 550.00
TownLibrary: 450.00
Library with most books: CityLibrary

5. Test Case 2

Input:
1
103
CollegeLibrary
3
204
OS
Tanmay
300.0
290
205
DBMS
Ravi
350.0
310
206
CN
Kiran
400.0
270
300
Output:
Books with pages > 300:
205 DBMS
Average book price:
CollegeLibrary: 350.00
Library with most books: CollegeLibrary

💻 Laptop Inventory System


Manage laptop models available in various stores.

📦 Classes:
 Class: Laptop (laptopId: int, model: String, brand: String, ramSize: int, price: double)
 Class: Store (storeId: int, storeName: String, laptops: List<Laptop>)

🎯 Tasks:
6. Find the most expensive laptop in each store.
7. Filter laptops by RAM size.
8. Find the store with the highest total laptop value.

🔤 Input Format:
First line: Integer n (number of stores)
For each store:
Store ID, Store Name, Number of laptops
For each laptop: Laptop ID, Model, Brand, RAM Size, Price
Last line: RAM size threshold

📤 Output Format:
List of laptops with RAM >= threshold
Most expensive laptop in each store
Store with highest total laptop value

🧪 Sample Test Cases:


9. Test Case 1

Input:
2
1
ElectroHub
2
101
ThinkPad
Lenovo
8
70000.0
102
MacBook
Apple
16
150000.0
2
GadgetWorld
1
103
Pavilion
HP
8
60000.0
8

Output:
Laptops with RAM >= 8:
101 ThinkPad
102 MacBook
103 Pavilion
Most expensive laptops:
ElectroHub: MacBook
GadgetWorld: Pavilion
Store with highest value: ElectroHub

10. Test Case 2

Input:
1
3
LaptopBazaar
2
201
XPS
Dell
16
120000.0
202
Inspiron
Dell
4
50000.0
12
Output:
Laptops with RAM >= 12:
201 XPS
Most expensive laptops:
LaptopBazaar: XPS
Store with highest value: LaptopBazaar

🏫 Student Course Enrollment System


Track student enrollment in different courses.

📦 Classes:
 Class: Student (studentId: int, name: String, age: int)
 Class: Course (courseId: int, courseName: String, students: List<Student>)

🎯 Tasks:
11. Find the average age of students in a course.
12. Find the course with the most students.
13. Print a message if a course has no students.

🔤 Input Format:
First line: Integer n (number of courses)
For each course:
Course ID, Course Name, Number of students
For each student: Student ID, Name, Age
Last line: Course ID to calculate average age for

📤 Output Format:
Average age of students in selected course
Course with most students

🧪 Sample Test Cases:


14. Test Case 1

Input:
2
101
Java
2
201
Alice
20
202
Bob
22
102
Python
1
203
Charlie
21
101

Output:
Average age of students: 21.00
Course with most students: Java

15. Test Case 2

Input:
1
103
C++
0
103

Output:
No students enrolled in course: C++
Course with most students: C++

✈️Travel Agency Booking System


Manage traveler records under different travel agencies.

📦 Classes:
 Class: Traveler (travelerId: int, name: String, destination: String, budget: double)
 Class: Agency (agencyId: int, agencyName: String, travelers: List<Traveler>)

🎯 Tasks:
16. Count travelers going to a specific destination.
17. Find agency with most travelers.
18. Calculate average budget of travelers in each agency.

🔤 Input Format:
First line: Integer n (number of agencies)
For each agency:
Agency ID, Name, Number of travelers
For each traveler: ID, Name, Destination, Budget
Last line: Destination name to filter
📤 Output Format:
Count of travelers to destination
Average budget per agency
Agency with most travelers

🧪 Sample Test Cases:


19. Test Case 1

Input:
2
1
HolidayTours
2
101
Amit
Paris
100000
102
Rita
Rome
80000
2
DreamTravels
1
103
Sohan
Paris
120000
Paris

Output:
Travelers to Paris: 2
Average budgets:
HolidayTours: 90000.00
DreamTravels: 120000.00
Agency with most travelers: HolidayTours

20. Test Case 2

Input:
1
3
FunRides
1
104
Anita
Dubai
70000
London

Output:
Travelers to London: 0
Average budgets:
FunRides: 70000.00
Agency with most travelers: FunRides

🏥 Hospital Appointments System (Extended)


Track doctor-patient appointments.

📦 Classes:
 Class: Appointment (appointmentId: int, doctorId: int, patientId: int, date: String)
 Class: Doctor (doctorId: int, name: String)
 Class: Patient (patientId: int, name: String)

🎯 Tasks:
21. Print all appointments for a doctor.
22. Count appointments on a specific date.
23. Find doctor with most appointments.

🔤 Input Format:
First line: Integer n (number of appointments)
For each: Appointment ID, Doctor ID, Patient ID, Date
Last line: Doctor ID and Date to search

📤 Output Format:
Appointments for selected doctor
Count for selected date
Doctor with most appointments

🧪 Sample Test Cases:


24. Test Case 1

Input:
3
1
101
201
2024-01-10
2
102
202
2024-01-11
3
101
203
2024-01-10
101
2024-01-10

Output:
Appointments for Doctor 101:
201, 203
Appointments on 2024-01-10: 2
Doctor with most appointments: 101

25. Test Case 2

Input:
2
4
103
205
2024-02-12
5
104
206
2024-02-15
104
2024-02-12

Output:
Appointments for Doctor 104:
206
Appointments on 2024-02-12: 1
Doctor with most appointments: 103

You might also like