0% found this document useful (0 votes)
5 views5 pages

Java Practice Questions

The document outlines three Java practice questions focused on designing systems for inventory management, library book management, and course feedback. Each question requires the creation of classes with specific attributes, constructors, and service methods to handle various functionalities, including cost calculations, item listings, and feedback ratings. Sample inputs and outputs are provided to illustrate expected behavior and error handling for negative values.
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)
5 views5 pages

Java Practice Questions

The document outlines three Java practice questions focused on designing systems for inventory management, library book management, and course feedback. Each question requires the creation of classes with specific attributes, constructors, and service methods to handle various functionalities, including cost calculations, item listings, and feedback ratings. Sample inputs and outputs are provided to illustrate expected behavior and error handling for negative values.
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

JAVA PRACTICE QUESTIONS

1. Java Inventory Management - ADVANCED

Design a system with two classes: `Warehouse` and `Shipment`.


Each Warehouse has:
- warehouseId: Integer
- warehouseName: String
- numberOfShipments: Integer
- shipments: List of Shipment objects

Each Shipment has:


- shipmentId: Integer
- itemName: String
- costPerItem: Double
- quantity: Integer

Tasks:
1. Create classes with attributes, parameterized constructors, and getters/setters.
2. Create a Service class with:
a) `calculateTotalShipmentCostByQuantity(List<Warehouse>, int quantity)`
- Print the total shipment cost for all items with quantity greater than the given number.
- If costPerItem is negative, throw `InvalidCostException` with message "Invalid Cost: Cost
cannot be negative."
- If no such shipments exist, print "No Shipment Found."
b) `listItemsByWarehouseId(List<Warehouse>, int warehouseId)`
- Print all item names from shipments in the given warehouseId.
- If not found, print "No Items Found."

Sample Input:
2
1001
Central
2
501
Laptops
50000.0
4
502
Phones
-20000.0
2
1002
South
1
503
Monitors
15000.0
5
3
1001

Sample Output:
Invalid Cost: Cost cannot be negative.
Total Shipment Cost of items with quantity > 3 is 200000.0
Item Names in Warehouse ID 1001:
Laptops
Phones

2. Java Library Book System

Design a system with two classes: `Library` and `Book`.


Each Library has:
- libraryId: Integer
- libraryName: String
- totalBooks: Integer
- books: List of Book objects

Each Book has:


- bookId: Integer
- title: String
- price: Double
- pages: Integer

Tasks:
1. Create constructors, getters, setters.
2. In `LibraryService` class, implement:
a) `getBooksCostlierThan(List<Library>, double minPrice)`
- Print titles of books that cost more than minPrice.
- If price < 0, throw `NegativePriceException`.
- If no book matches, print "No Expensive Books Found."
b) `getTitlesByLibraryId(List<Library>, int id)`
- Case-insensitive match. If not found, print "No Books Found".

Sample Input:
2
2001
CityLibrary
2
301
Java Basics
300.0
250
302
Advanced Python
-450.0
320
2002
UniLibrary
1
303
Data Structures
700.0
400
400.0
2002

Sample Output:
NegativePriceException: Price cannot be negative.
Books priced above 400.0:
Data Structures
Book Titles in Library ID 2002:
Data Structures

3. Java Course Feedback Portal

Design a feedback portal using classes: `Course` and `Feedback`.


Each Course has:
- courseId: Integer
- courseName: String
- feedbacks: List of Feedback objects

Each Feedback has:


- feedbackId: Integer
- studentName: String
- rating: Double
- review: String

Tasks:
1. Create all attributes with proper constructor, getter and setter.
2. Create `FeedbackService` class with:
a) `getAverageRatingAboveThreshold(List<Course>, double threshold)`
- Print course names whose average feedback rating is above threshold.
- If no course matches, print "No High Rated Courses."
b) `listReviewersByCourseId(List<Course>, int id)`
- Print reviewer names for a course with the given ID.
- If rating is negative, throw `InvalidRatingException` with message "Rating cannot be negative."
- If no reviewers, print "No Reviewers Found."

Sample Input:
2
501
Spring Boot
2
601
Alice
4.5
Excellent content
602
Bob
-3.2
Too basic
502
Angular
1
603
Charlie
4.0
Good
4.0
502

Sample Output:
InvalidRatingException: Rating cannot be negative.
Courses with average rating above 4.0:
Angular
Reviewers in Course ID 502:
Charlie

You might also like