Skip to content

Simulates Online travel company. That provides, airplane seat reservation, train seat reservation, hotel room reservation and meal booking

License

Notifications You must be signed in to change notification settings

voyager2005/Travelocity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Travelocity

GitHub issues GitHub repo size GitHub language count


This is a program that I did as my school assignment. This contains 7 classes that are interlinked wiht each other
I have tried my best to include exception handling for each input. Let me know in the comments if there are any parts of the program that do not have exception handling

Feel free to contact me on my mail. Do not forget to ⭐ this repository of you liked it so that more people can benefit from this code.

Announcements 🔊:

Some updates as of 4:09pm 20-01-21
• based on request from friends and all the mails I will be creating individual code samples of all the above class. Hopefully I can complete that within a few weeks. Thanks
• I have already created one for AirplaneSeatReservation. You can view that repository here

Key:

License and copyright
Output
Exception Handling
Thread.sleep(<time_in_millisecods>);

License and copyright

© Akshat G
Licensed under MIT license

Output

1. [layout]:
image1 2. starting the program:
image2
image3
3. Output: image4 image5 image6 image7 image8 image9 image10

Exception Handling:

  1. while accepting the phone number, phone numbers length should be 10 digits long. the check for that is as follows:
System.out.println("Phone Number: ");
        System.out.println();
        phoneNumber = sc.nextLine().trim(); 
        if( phoneNumber.length() != 10)
        {
            boolean flag = false; 
            while(flag == false)
            {
                System.out.println("Please make sure that the phone number that you have entered is 10 digits long" + 
                "\nThe phone number entered by you was " + phoneNumber.length() + " digits long");
                phoneNumber = sc.nextLine().trim();
                
                if(phoneNumber.length() == 10)
                {
                    flag = true; 
                }
            }
        }
  1. cannot book the seat that you have already booked in AirplaneSeatReservation
    There are a 2 sets of arrays that are used to hold the numerical and the character value of the seat, note: variables are not the same as to the program. lets take that the user had entered 1F which has not been booked
seat = sc.nextLine().trim()

now we are using the charAt() method to remove the numerical and character part of the string

char numerical = seat.charAt(0); 
char character = seat.charAt(1); 

now we check if any of the reserved seats match the numerical and character

for( int i = 0 ; i < reservedSeatsNumerical.length; i++)
{
  if(reservedSeatNumerical[i] == numerical && reservedSeatCharacter[i] == character)
  {
    System.out.println(seat + " has already been reserved); 
  }
}

To prevent the user from booking that seat again we do this, there are a total of 25 predefined reserved seats in my program, so I have a variable index which stores the total no of reserve seats, ie: index = 24. note: this is in the else part of the above code

else
{
  index++; 
  reservedSeatNumerical[index] = numerical;
  reservedSeatCharacter[index] = character; 
}

now the user will not be able to book that seat again

Thread.sleep(<time_in_millisecods>);

Thread.sleep(<time_in_milliseconds>) causes errors if used directly. To attain an output like someone is typing the code on the terminal you need to use this code:

  1. declare a string that contains the code that you want to print on the terminal
String line1 = "what is your name?"; 
  1. now you need to add a loop to print this word by word.
for(int i = 0; i < line1.length() ; i++)
{
  char ch = line1.charAt(i); 
  System.out.print(ch)
}

Here you are printing word by word but since java is an extremely fast language you will not be able to differentiate directly printing and printing like this so...
now we add a try{ } catch(){ } block to add delays in the loop

for(int i = 0; i < line1.length() ; i++)
{
  char ch = line1.charAt(i); 
  System.out.print(ch)
  
  try
  {
    Thread.sleep(25);
  }
  catch(Exception e)
  {
  }
}

The updated loop will look something like this ↑.

About

Simulates Online travel company. That provides, airplane seat reservation, train seat reservation, hotel room reservation and meal booking

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages