πŸ’» Unit 3 Project: Travel Booking System

Overview & Setup

✈️ You are a software engineer for a high-end travel agency, β€œWanderlust Solutions.” Your task is to create a system that tracks custom travel bookings, using object-oriented class design.

While the theme is travel, you have the creative freedom to decide what kind of travel item you are modeling, for example:

  • All-Inclusive Vacation Package πŸ–οΈ
  • Space Tourism Ticket πŸš€
  • Backpacking Adventure πŸŽ’
  • Luxury Cruise 🚒
  • Disney Trip πŸ‘‘
  • Teen Tour 🧳
πŸ“₯ PROJECT PROGRAM SETUP INSTRUCTIONS
  1. Go to the public template repository for our class: BWL-CS Java Template
  2. Click the button above the list of files then select Create a new repository
  3. Specify the repository name: CS2-Booking-System
  4. Click

    Now you have your own personal copy of this starter code that you can always access under the Your repositories section of GitHub!

  5. Now on your repository, click and select the Codespaces tab
  6. Click Create Codespace on main and wait for the environment to load, then you’re ready to code!
  7. πŸ“ Write code in this Codespace during class.

PART A: Define the Travel Class

Leave the Main class alone for now and create another class to represent a travel booking object. Define this class as described below. All variables should be declared as private and all methods as public.

CLASS NAME:

  • Choose a name that fits your specific trip theme (e.g., VacationPackage, TeenTour, etc.)

STATIC VARIABLE:

  • processingFeePerDay = 45 (this represents a flat daily fee for the travel agency, feel free to adjust the value to reflect a higher or lower standard of service).

INSTANCE VARIABLES:

Declare at least six private instance variables.

  1. travelerName (String)
  2. destination (String)
  3. durationInDays (int)
  4. Your choice of boolean (e.g., isInternational)
  5. Your choice of double (e.g., starRating, luggageWeight)
  6. totalPackageCost (double) β†’ this will be a calculated field

INSTANCE METHODS:

  1. Default Constructor: Sets generic default values for all fields (instance variables).
  2. Parameterized Constructor: Accepts arguments for the first four variables (use the same variable names for the parameters as the instance variables).
    • Calculation: The totalPackageCost should be set by multiplying the durationInDays by the static processingFeePerDay.
  3. Accessor Methods: β€œGetters” for every data field.
  4. Mutator Methods: β€œSetters” for every data field.
    • The Cost Mutator: The mutator for totalPackageCost must accept durationInDays as a parameter and recalculate the cost using the static processingFeePerDay.
  5. toString(): Returns a formatted, multi-line string that represents the object’s state. Use creative labels like --- TRIP ITINERARY FOR [Name] ---. See below for an example.

Example String Representation:

public String toString() {
  String itinerary = "-----------------------------------------\n" +
                     "       βœ¨β›ΊοΈ GLAMPING ITINERARY β›ΊοΈβœ¨        \n" +
                     "-----------------------------------------\n" +
                     "GUEST NAME:    " + travelerName + "\n" +
                     "DESTINATION:   " + destination + "\n" +
                     "STAY DURATION: " + durationInDays + " Nights\n" +
                     "LUXURY RATING: " + tentLuxuryRating + " / 5.0 ⭐️\n" +
                     "-----------------------------------------\n" +
                     "TOTAL COST:  $" + totalPackageCost + ".00\n" +
                     "-----------------------------------------\n" +
                     "  Thank you for booking with Wanderlust! \n";
  return itinerary;  
}

PART B: Test the System

Complete the Main class to test your travel object:

Static Method for Creating Objects:

Write a static method below the main method (but inside the Main class) to create objects.

  • Method Name: bookTrip
  • Return Type: An object whose β€œdata type” is the name of the custom class you wrote in Part A (e.g., VacationPackage, TeenTour, etc.)
  • Parameter: It must accept a Scanner object from the main method.
  • Method Body:
    1. Start by creating a blank travel object using the default constructor.
    2. Ask the user for all the details (Name, Destination, Duration, and your custom variables).

      Do NOT ask for the total package cost, since this is a calculated value.

    3. Call all of your mutator methods to update the object’s values based on what the user typed.
    4. Return the completed travel object back to the main method.

Main Interaction Loop:

In the main method, set up the user interface:

  • Create a Scanner object called input.
  • Use a while loop controlled by a boolean flag variable called bookTrip.

πŸ” Inside the loop:

  1. Call your static bookTravel() method to create a new travel object.
  2. Display the object’s details using the toString() method.
  3. Ask the user: "Would you like to log another trip? (Y/N)".
  4. Use a Scanner method to accept user input, and store their response in a variable called response.
  5. Use an if-else conditional block to test their response, and set the boolean flag to either run the loop again, or exit.

Creative Requirements Checklist:

  • Does my class use a unique travel-related name?
  • Did I include a double and a boolean as instance variables?
  • Does my toString() look like an actual travel receipt or itinerary?
  • Did I remember to use this.variableName in my parameterized constructor?

You can also turn your text-based interactive version into a visual one with a GUI (Graphical User Interface)! See my Java Swing demo: GitHub Swing GUI and make sure to copy your completed class file in the repository too.