π» 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
- Go to the public template repository for our class: BWL-CS Java Template
- Click the button above the list of files then select
Create a new repository - Specify the repository name:
CS2-Booking-System - Click
Now you have your own personal copy of this starter code that you can always access under the
Your repositoriessection of GitHub! - Now on your repository, click and select the
Codespacestab - Click
Create Codespace on mainand wait for the environment to load, then youβre ready to code! - π 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.
travelerName(String)destination(String)durationInDays(int)- Your choice of boolean (e.g.,
isInternational) - Your choice of double (e.g.,
starRating,luggageWeight) totalPackageCost(double) β this will be a calculated field
INSTANCE METHODS:
- Default Constructor: Sets generic default values for all fields (instance variables).
- Parameterized Constructor: Accepts arguments for the first four variables (use the same variable names for the parameters as the instance variables).
- Calculation: The
totalPackageCostshould be set by multiplying thedurationInDaysby the staticprocessingFeePerDay.
- Calculation: The
- Accessor Methods: βGettersβ for every data field.
- Mutator Methods: βSettersβ for every data field.
- The Cost Mutator: The mutator for
totalPackageCostmust acceptdurationInDaysas a parameter and recalculate the cost using the staticprocessingFeePerDay.
- The Cost Mutator: The mutator for
- 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
Scannerobject from the main method. - Method Body:
- Start by creating a blank travel object using the default constructor.
- 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.
- Call all of your mutator methods to update the objectβs values based on what the user typed.
- Return the completed travel object back to the
mainmethod.
Main Interaction Loop:
In the main method, set up the user interface:
- Create a
Scannerobject calledinput. - Use a
whileloop controlled by abooleanflag variable calledbookTrip.
π Inside the loop:
- Call your static
bookTravel()method to create a new travel object. - Display the objectβs details using the
toString()method. - Ask the user:
"Would you like to log another trip? (Y/N)". - Use a
Scannermethod to accept user input, and store their response in a variable calledresponse. - Use an
if-elseconditional block to test their response, and set thebooleanflag to either run the loop again, or exit.
Creative Requirements Checklist:
- Does my class use a unique travel-related name?
- Did I include a
doubleand abooleanas instance variables? - Does my
toString()look like an actual travel receipt or itinerary? - Did I remember to use
this.variableNamein 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.