import java.util.Scanner;
public class TravelProgram1
{
//Declare and initialize all CLASS CONSTANTS
public static final String DESTINATION_NAME_ROME = "Rome, Italy";
public static final String DESTINATION_NAME_LONDON = "London, England";
public static final String DESTINATION_NAME_KEYWEST = "Key West, Florida";
public static final String DESTINATION_NAME_QUIT = "Quit program";
public static final double DESTINATION_PRICE_ROME = 500.00;
public static final double DESTINATION_PRICE_LONDON = 500.00;
public static final double DESTINATION_PRICE_KEYWEST = 500.00;
public static final String TRANSPORTATION_NAME_AIRPLANE = "Airplane";
public static final String TRANSPORTATION_NAME_SHIP = "Ship";
public static final double TRANSPORTATION_PRICE_AIRPLANE = 500.00;
public static final double TRANSPORTATION_PRICE_SHIP = 250.00;
public static final String UPGRADE_NAME_TRANSPORTATION = "Transportation Upgrade";
public static final String UPGRADE_NAME_LODGING = "Lodging Upgrade";
public static final String UPGRADE_NAME_TOURS = "Tour Upgrade";
public static final String UPGRADE_NAME_ALL = "All Upgrades";
public static final String UPGRADE_NAME_NONE = "No Upgrades";
public static final double UPGRADE_PRICE_TRANSPORTATION = 75.00;
public static final double UPGRADE_PRICE_LODGING = 125.00;
public static final double UPGRADE_PRICE_TOURS = 50.00;
public static final double UPGRADE_PRICE_ALL = 200.00;
public static final double UPGRADE_PRICE_NONE = 0.0;
public static void main(String[] args)
{
//Declare and initialize a Scanner object
Scanner input = new Scanner(System.in);
//Declare and initialize all MAIN method variables
String userName = "";
char destinationSelection = ' ';
char transportationSelection = ' ';
char upgradeSelection = ' ';
String destinationName = "";
String transportationName = "";
String upgradeName = "";
double lodgingCost = 0.0;
double transportationCost = 0.0;
double upgradeCost = 0.0;
double tripCost = 0.0;
int counterRome = 0;
int counterLondon = 0;
int counterKeyWest = 0;
int tripCounter = 0;
double totalTripSales = 0.0;
//Welcome Banner
displayWelcomeBanner();
//User input for user name
System.out.println("\nTo begin, what is your name?");
userName = input.next();
System.out.println("");
System.out.println("Thank you " + userName + "!");
System.out.println("");
//Invoke Destination method menu
destinationSelection = validateDestinationSelection(input);
//Run while not quit repetition structure
while (destinationSelection != 'Q')
{
//Invoke transportation menu method
transportationSelection = validateTransportationSelection(input);
System.out.println("********************************************************************************************************");
System.out.println("Please take note of the following: ");
System.out.println("");
System.out.println("If no upgrades are selected, travel will include economy seats and a stay in a standard room!");
System.out.println("");
System.out.println("Each trip can include only 1 upgrade selection!");
System.out.println("");
System.out.println("The 'All Upgraded Services' option is a special deal; cost for all options is regularly $250.00!");
System.out.println("********************************************************************************************************");
//Invoke upgrade menu method
upgradeSelection = validateUpgradeSelection(input);
//Start of if/else menu selection
if (destinationSelection == 'A')
{
destinationName = DESTINATION_NAME_ROME;
lodgingCost = DESTINATION_PRICE_ROME;
counterRome++;
}
else if (destinationSelection == 'B')
{
destinationName = DESTINATION_NAME_LONDON;
lodgingCost = DESTINATION_PRICE_LONDON;
counterLondon++;
}
else
{
destinationName = DESTINATION_NAME_KEYWEST;
lodgingCost = DESTINATION_PRICE_KEYWEST;
counterKeyWest++;
}
if (transportationSelection == 'A')
{
transportationName = TRANSPORTATION_NAME_AIRPLANE;
transportationCost = TRANSPORTATION_PRICE_AIRPLANE;
}
else
{
transportationName = TRANSPORTATION_NAME_SHIP;
transportationCost = TRANSPORTATION_PRICE_SHIP;
}
if (upgradeSelection == 'A')
{
upgradeName = UPGRADE_NAME_TRANSPORTATION;
upgradeCost = UPGRADE_PRICE_TRANSPORTATION;
}
else if (upgradeSelection == 'B')
{
upgradeName = UPGRADE_NAME_LODGING;
upgradeCost = UPGRADE_PRICE_LODGING;
}
else if (upgradeSelection == 'C')
{
upgradeName = UPGRADE_NAME_TOURS;
upgradeCost = UPGRADE_PRICE_TOURS;
}
else if (upgradeSelection == 'D')
{
upgradeName = UPGRADE_NAME_ALL;
upgradeCost = UPGRADE_PRICE_ALL;
}
else
upgradeName = UPGRADE_NAME_NONE;
upgradeCost = UPGRADE_PRICE_NONE;
//Output Trip report
displayTripReport(destinationName, lodgingCost, transportationName, transportationCost, upgradeName, upgradeCost, tripCost);
destinationSelection = validateDestinationSelection(input);
}//End of run while not Quit
//Calculations
tripCost = lodgingCost + transportationCost + upgradeCost;
tripCounter = counterRome + counterLondon + counterKeyWest;
totalTripSales = totalTripSales + tripCost;
//Final report
if (tripCounter > 0)
{
displayFinalReport(counterRome, counterLondon, counterKeyWest, tripCounter, totalTripSales);
}
input.close();
}//End of Main Method
public static char validateDestinationSelection(Scanner borrowedInput) //Scanner is declared and renamed
{//Start of validateDestinationSelection
//Initialize local variables
char localDestinationSelection = ' ';
System.out.printf("%-30s\n", "Destination Menu:");
System.out.println("********************************************************************************************************");
System.out.printf("%-4s%-25s%-2s%5.2f%s\n", "[A]:", DESTINATION_NAME_ROME,"$", DESTINATION_PRICE_ROME,"/5 day stay");
System.out.printf("%-4s%-25s%-2s%5.2f%s\n", "[B]:", DESTINATION_NAME_LONDON,"$", DESTINATION_PRICE_LONDON,"/5 day stay");
System.out.printf("%-4s%-25s%-2s%5.2f%s\n", "[C]:", DESTINATION_NAME_KEYWEST,"$", DESTINATION_PRICE_KEYWEST,"/5 day stay");
System.out.println("[Q] to Quit Program. ");
System.out.println("*********************************************************************************************************");
System.out.println("Please enter your selection here: ");
//User input collected with borrowed Scanner
localDestinationSelection = borrowedInput.next().toUpperCase().charAt(0);
//Validate input
while (localDestinationSelection !='A' && localDestinationSelection !='B' && localDestinationSelection !='C' && localDestinationSelection !='Q')
{
//Error message
System.out.printf("%-30s\n", "Invalid option! Please select a valid option from the menu.");
System.out.println("*********************************************************************************************************");
//Main Menu
System.out.printf("%-30s\n", "Main Menu:");
System.out.println("********************************************************************************************************");
System.out.printf("%-4s%-25s%-2s%5.2f%s\n", "[A]:", DESTINATION_NAME_ROME,"$", DESTINATION_PRICE_ROME,"/5 day stay");
System.out.printf("%-4s%-25s%-2s%5.2f%s\n", "[B]:", DESTINATION_NAME_LONDON,"$", DESTINATION_PRICE_LONDON,"/5 day stay");
System.out.printf("%-4s%-25s%-2s%5.2f%s\n", "[C]:", DESTINATION_NAME_KEYWEST,"$", DESTINATION_PRICE_KEYWEST,"/5 day stay");
System.out.println("Press [Q] to quit program.");
System.out.println("*********************************************************************************************************");
System.out.println("Please enter your selection here: ");
localDestinationSelection = borrowedInput.next().toUpperCase().charAt(0);
}//End of menu validation loop
return localDestinationSelection;
}//End of validateDestinationSelection
public static char validateTransportationSelection(Scanner borrowedInput)//Scanner is declared and renamed
{//Start of validateTranportationSelection
//Initialize local variables
char localTransportationSelection = ' ';
//Transportation Menu
System.out.printf("%-30s\n", "Transportation Menu:");
System.out.println("********************************************************************************************************");
System.out.printf("%-4s%-25s%-2s%5.2f%s\n", "[A]:", TRANSPORTATION_NAME_AIRPLANE,"$", TRANSPORTATION_PRICE_AIRPLANE," per seat");
System.out.printf("%-4s%-25s%-2s%5.2f%s\n", "[B]:", TRANSPORTATION_NAME_SHIP,"$", TRANSPORTATION_PRICE_SHIP," per seat");
System.out.println("*********************************************************************************************************");
System.out.println("Please enter your selection here: ");
//User input borrowed from Scanner
localTransportationSelection = borrowedInput.next().toUpperCase().charAt(0);
//Validate input
while (localTransportationSelection != 'A' && localTransportationSelection != 'B')
{
//Error message
System.out.printf("%-30s\n", "Invalid option! Please select a valid option from the menu.");
System.out.printf("%-30s\n", "Transportation Menu:");
System.out.println("********************************************************************************************************");
System.out.printf("%-4s%-25s%-2s%5.2f%s\n", "[A]:", TRANSPORTATION_NAME_AIRPLANE,"$", TRANSPORTATION_PRICE_AIRPLANE," per seat");
System.out.printf("%-4s%-25s%-2s%5.2f%s\n", "[B]:", TRANSPORTATION_NAME_SHIP,"$", TRANSPORTATION_PRICE_SHIP," per seat");
System.out.println("*********************************************************************************************************");
System.out.println("Please enter your selection here: ");
//User input borrowed from Scanner
localTransportationSelection = borrowedInput.next().toUpperCase().charAt(0);
}//End of Transportation menu validation loop
return localTransportationSelection;
}//End of validateTransportationSelection
public static char validateUpgradeSelection(Scanner borrowedInput)
{
char localUpgradeSelection = ' ';
System.out.printf("%-30s\n", "Upgrade Menu:");
System.out.println("********************************************************************************************************");
System.out.printf("%-4s%-25s%-2s%5.2f%s\n", "[A]:", UPGRADE_NAME_TRANSPORTATION,"$", UPGRADE_PRICE_TRANSPORTATION," per seat");
System.out.printf("%-4s%-25s%-2s%5.2f%s\n", "[B]:", UPGRADE_NAME_LODGING,"$", UPGRADE_PRICE_LODGING," per room");
System.out.printf("%-4s%-25s%-2s%5.2f\n", "[C]:", UPGRADE_NAME_TOURS,"$", UPGRADE_PRICE_TOURS);
System.out.printf("%-4s%-25s%-2s%5.2f\n", "[D]:", UPGRADE_NAME_ALL,"$", UPGRADE_PRICE_ALL);
System.out.printf("%-4s%-25s%-2s%5.2f\n", "[E]:", UPGRADE_NAME_NONE,"$", UPGRADE_PRICE_NONE);
System.out.println("*********************************************************************************************************");
System.out.println("Please enter your selection here: ");
localUpgradeSelection = borrowedInput.next().toUpperCase().charAt(0);
//Upgrade menu validation
while (localUpgradeSelection != 'A' && localUpgradeSelection != 'B'&& localUpgradeSelection != 'C' && localUpgradeSelection != 'D' && localUpgradeSelection != 'E')
{
//Error message
System.out.printf("%-30s\n", "Invalid option! Please select a valid option from the menu.");
System.out.printf("%-30s\n", "Upgrade Menu:");
System.out.println("********************************************************************************************************");
System.out.printf("%-4s%-25s%-2s%5.2f%s\n", "[A]:", UPGRADE_NAME_TRANSPORTATION,"$", UPGRADE_PRICE_TRANSPORTATION," per seat");
System.out.printf("%-4s%-25s%-2s%5.2f%s\n", "[B]:", UPGRADE_NAME_LODGING,"$", UPGRADE_PRICE_LODGING," per room");
System.out.printf("%-4s%-25s%-2s%5.2f\n", "[C]:", UPGRADE_NAME_TOURS,"$", UPGRADE_PRICE_TOURS);
System.out.printf("%-4s%-25s%-2s%5.2f\n", "[D]:", UPGRADE_NAME_ALL,"$", UPGRADE_PRICE_ALL);
System.out.printf("%-4s%-25s%-2s%5.2f\n", "[E]:", UPGRADE_NAME_NONE,"$", UPGRADE_PRICE_NONE);
System.out.println("*********************************************************************************************************");
System.out.println("Please enter your selection here: ");
localUpgradeSelection = borrowedInput.next().toUpperCase().charAt(0);
}//End of menu validation
return localUpgradeSelection;
}//End of validateUpgradeSelection
public static void displayWelcomeBanner()
{//Welcome Banner method
System.out.println("Welcome to the Travel Program!");
System.out.println("This program will let you set up a 5 day vacation with added on options.");
System.out.println("***********************************************************************************");
}//End of Welcome Banner method
public static void displayTripReport(String borrowedDestinationName, double borrowedLodgingCost, String borrowedTransportationName, double borrowedTransportationCost, String borrowedUpgradeName, double borrowedUpgradeCost, double borrowedTripCost)
{
System.out.println("*******************************************************************************");
System.out.printf("%-30s%s\n", "Destination: ", borrowedDestinationName);
System.out.printf("%-30s%1s%8.2f\n", "Lodging Cost: ", "$" , borrowedLodgingCost);
System.out.println("");
System.out.printf("%-30s%s\n", "Transportation: ", borrowedTransportationName);
System.out.printf("%-30s%1s%8.2f\n", "Transportation Cost: ", "$" , borrowedTransportationCost);
System.out.println("");
System.out.printf("%-30s%s\n", "Upgrade: ", borrowedUpgradeName);
System.out.printf("%-30s%1s%8.2f", "Upgrade Cost: ", "$" , borrowedUpgradeCost);
System.out.println("");
System.out.printf("%-30s%1s%8.2f\n", "Trip Cost: " , "$" , borrowedTripCost);
System.out.println("*********************************************************************************");
}//End displayTripReport
public static void displayFinalReport(int counterRome, int counterLondon, int counterKeyWest, int tripCounter, double totalTripSales)
{
System.out.println("******************************************************************************************");
System.out.println("Final Report");
System.out.println("*******************************************************************************************");
System.out.printf("%-30s%1s\n", "Count of Rome, Italy","","Trips: ",counterRome );
System.out.printf("%-30s%1s\n", "Count of London, England","","Trips: ", counterLondon);
System.out.printf("%-30s%1s\n", "Count of Key West, Florida","","Trips: ", counterKeyWest);
System.out.println("");
System.out.printf("%-30s%1s\n", "Count of all trips: ", tripCounter);
System.out.println("");
System.out.printf("%-30s%1s%8.2f\n", "Total Trip Sales: " , "$" , totalTripSales);
System.out.println("*******************************************************************************************");
}
public static void displayFarewellMessage()
{
System.out.println("\nThank you for using The Travel Program!");
System.out.println("Have a wonderful day!");
}
}