Building Reusable Booking Operations for SkyReserve using static functions

Business Scenario

Welcome back,Developers!

In the previous lab, we organized the SkyReserve Flight Booking System into reusable methods. The application can now accept booking details, calculate ticket fares, and display the booking information efficiently.

But there's one important problemwhat if users enter invalid information?

Imagine a passenger tries to book 0 tickets, -2 tickets, or 10 tickets when the airline allows only 5 tickets per booking.

Should the system continue with the booking? Of course not!

Your next task is to validate user inputs using conditional statements, ensuring only valid bookings are accepted

Pre-Lab Preparation

git pull origin branchName

Git Pull

Task 1: Checking number of passengers

1

Declaring static variables to store user inputs

Topic :

1) Relational Operators and Logical Operators

2) Defining conditions using relational operators

3) Conditional statements - if, if-else, nesting, switch-case

Accordingly, if the booking status is true, then display the booking information from main. But if the booking is not done, the booking information need not be displayed through main

2

Run the code. 

3

If user enters negative or zero for passenger count, check the output

a

b

If user enters positive value for passenger count, check the output

Task 2: Checking passenger count

Change the  if condition in setBookingDetails() using logical operator

1

Run the code and check the output, by providing passenger count more than 5

2

Task 2: Calculating the total ticket price

For applying discount, based on the user category, we need to declare the switch-case. However, the discount is applicable, only if the passenger count is valid. So we need to declare switch-case within the if block.

Add switch-case within if

1

2

Change the calculate method as shown below

Run the code and check the output

3

If the entered category is other than “'regular' or 'student' or 'armed forces'” then the error will be displayed

4

 

Great job!
You have successfully implemented input validation using conditional statements. Your SkyReserve booking system now accepts only valid booking requests.

Checkpoint

Next-Lab Preparation

Topic :

1) Understanding of Loops

2) Conditional statements - if, if-else, nesting, switch-case

   Git Push

git push origin branchName