0% found this document useful (0 votes)
60 views11 pages

03 SBQ RoomReservation ArrayList Exceptions

The document outlines the creation of a Hotel class with specific attributes and methods for room booking and finding maximum capacity rooms based on availability. It includes a Solution class with a main method that handles user input and calls the static methods for room booking and capacity checks. Additionally, it describes a custom exception class for handling cases where no even integers are found in a collection, along with sample test cases for clarity.

Uploaded by

kadhalbeats25
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)
60 views11 pages

03 SBQ RoomReservation ArrayList Exceptions

The document outlines the creation of a Hotel class with specific attributes and methods for room booking and finding maximum capacity rooms based on availability. It includes a Solution class with a main method that handles user input and calls the static methods for room booking and capacity checks. Additionally, it describes a custom exception class for handling cases where no even integers are found in a collection, along with sample test cases for clarity.

Uploaded by

kadhalbeats25
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
You are on page 1/ 11

Use the appropriate collection to solve this question.

Create a class Hotel with the following private attributes

roomno – int

roomType – String

capacity – int

pricePerNight - double

isAvailable – boolean

Include a constructor and required getter and setter methods.

In a separate Solution class with the main method, implement the following
static methods:

 roomBookingByUsingRoomNo:
o This method should take collection of Hotel objects and
roomid(int) as input parameters and returns a Hotel object, if
the room is found and available or else, return null.
o Once room is found and available, then change the isAvailable
attribute to false.

 findMaxCapacityRoomsBasedOnAvailability:
o This method should take collection of Hotel objects as input
parameter and returns a Hotel object with maximum capacity if
any room is available or else, return null.

The above static methods should be called from the main method.

For roomBookingByUsingRoomNo: This main method should print the


Hotel object (roomid, roomType, capacity, pricePerNight) if object is not null
or else, print “No room found with given attributes”.
For findMaxCapacityRoomsBasedOnAvailability: This main method
should print the details of Hotel object (roomid, roomType, capacity,
pricePerNight) if returned object is not null or else, print “Rooms are not
available”.

Before calling the static methods in the main method, use the scanner
object to read value for no.of Hotel objects to be created, then read roomno,
roomType, capacity, pricePerNight, isAvailable for each Hotel object. Next,
read one Integer for capturing the roomid.

Constraints:

 Duplicate hotel objects are allowed and should follow insertion order.

For more clarity, refer to the sample input and output testcases which are
provided below.

Sample Test Case 0:


Input:

611

DoubleBedRoom

5300

false

612

TripleBedRoom

14

9300

true

614
SingleBedRoom

4400

false

613

DoubleBedRoom

6600

false

612

Output:

Room No: 612

Room Type: TripleBedRoom

Capacity: 14

Price: 9300.0

Rooms are not available

Explanation:

From the list of Hotel objects, the program has retruned 612 object and as per the
requirement the Hotel object is set to not available status. Now, while finding max
capacity, now the objects doesn’t have any available room. So the
findMaxCapacityRoomsBasedOnAvailability method returned null.

Sample Testcase 1:
Input:

182

SingleBedRoom
3

3000

true

184

SingleBedRoom

3450

true

183

DoubleBedRoom

5320

true

186

TripleBedRoom

10

7500

false

183

Output:

Room No: 183

Room Type: DoubleBedRoom

Capacity: 6

Price: 5320.0

Room No: 184

Room Type: SingleBedRoom

Capacity: 4
Price: 3450.0

Sample Test Case 2:


Input:

829

TripleBedRoom

12

9000

false

830

TripleBedRoom

14

9300

false

831

SingleBedRoom

4800

false

832

TripleBedRoom

15

10000

false
831

Output:

No room found with given attributes


Rooms are not available

Test Case 3:
Input:

740

DoubleBedRoom

5800

false

743

TripleBedRoom

14

9300

false

742

SingleBedRoom

4800

true

741

DoubleBedRoom

6300
true

740

Output:

No room found with given attributes


Room No: 741

Room Type: DoubleBedRoom

Capacity: 7

Price: 6300.0

Test Case 4:
Input:

740

DoubleBedRoom

5800

true

743

TripleBedRoom

14

9300

false

742

SingleBedRoom

4800
false

741

DoubleBedRoom

6300

false

740

Output:

Room No: 740

Room Type: DoubleBedRoom

Capacity: 8

Price: 5800.0

Rooms are not available

---------------------------------------------------------

Note on using the Scanner object:

Sometimes scanner object does not read the new line character by invoking
methods like nextInt(), nextDouble() etc.

Usually, this is not an issue, but this may be visible by calling nextLine()
method.

Consider the below input values:

1001

Savings

Refer the below code:


Scanner sc = new Scanner(System.in);

int x = sc.nextInt();

String str = sc.nextLine(); --> Here we expect str to have value Savings.
Instead, it may be like “”.

If the above issue is observed, then it is suggested to add one more explicit
call to nextLine() after reading numeric value.

------------------------------------------------------------------------------------------------------------
------

Create a custom exception class named “NotFoundException”

Write a main method in Solution class.

In this main method, read the integer values and store in the collection of
integers. From the collection of integers, you should get an average of
even numbers (in double value). If no even numbers found from respective
collection, then print the custom exception with message "Even Integers
are not available".

First read the integer value for size of collection. Next, read the sequence of
integers using Scanner object and store in the collection of type integer.

Constraint:
 Duplicate values are not allowed.
 During exception handling, catch block should throw the exception in the
specified format: “exception_class_name:<space>message_of_exception”.

Methods Used:
 (exception_variable_name).getClass().getSimpleName()
 (exception_variable_name).getMessage()

For more clarity, refer to the sample input and output test cases.

Sample Test Case 1


Input:
4
16
67
16
4

Output:
10.0

Sample Test Case 2


Input:
3
55
55
19

Output:
NotFoundException: Even Integers are not available

Sample Test Case 3


Input:
4
29
22
16
13

Output:
19.0

Sample Test Case 4


Input:
5
17
9
9
3
5
Output:
NotFoundException: Even Integers are not available

You might also like