Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 18 of 18

Thread: Trouble with outputs

  1. #1
    Junior Member
    Join Date
    Jul 2019
    Location
    South Carolina
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Trouble with outputs

    Hello everyone!

    I'm having some issues with my program. Its a pretty basic travel agency program. I have been debugging it for about a week now. The user selects an option on the Destination Menu. They then select an option in the Transportation menu followed by the Upgrade Menu. Then it is suppose to display a Trip Report showing the Destination, Lodging Cost, Transportation option, Transportation Price, Upgrade option, Upgrade cost and finally the total Trip Cost before repeating the menus for other trips. Then a final report with the count of Rome trips, London trips, Key West trips, count of all trips and finally total Trip Sales. The issues I'm having is the Upgrade cost as well as the Total Trip Cost isn't showing up! I'm also having issues with the Final Report now showing the count of trips for each destination. I have spent about 5 hours tweaking my code but I cannot figure out where I'm going wrong. Any help or guidance would be much appreciated!


    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!");
    	}
    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Trouble with outputs

    The issues I'm having is the Upgrade cost as well as the Total Trip Cost isn't showing up!
    Can you post the current output that shows what you are talking about?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jul 2019
    Location
    South Carolina
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Trouble with outputs

    Quote Originally Posted by Norm View Post
    Can you post the current output that shows what you are talking about?
    Yes, here you go!

    ************************************************** *****************************
    Destination: Rome, Italy
    Lodging Cost: $ 500.00

    Transportation: Airplane
    Transportation Cost: $ 500.00

    Upgrade: Lodging Upgrade
    Upgrade Cost: $ 0.00
    Trip Cost: $ 0.00
    ************************************************** *******************************

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Trouble with outputs

    Can you explain what is wrong with that output? Add some comments that shows what you are talking about.

    Also can you post the contents of the console window from when you execute the program that shows what the user's responses to the program are so they can be used for testing.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Jul 2019
    Location
    South Carolina
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Trouble with outputs

    Welcome to the Travel Program!
    This program will let you set up a 5 day vacation with added on options.
    ************************************************** *********************************

    To begin, what is your name?
    ty

    Thank you ty!

    Destination Menu:
    ************************************************** ************************************************** ****
    [A]:Rome, Italy $ 500.00/5 day stay
    [B]:London, England $ 500.00/5 day stay
    [C]:Key West, Florida $ 500.00/5 day stay
    [Q] to Quit Program.
    ************************************************** ************************************************** *****
    Please enter your selection here:
    a
    Transportation Menu:
    ************************************************** ************************************************** ****
    [A]:Airplane $ 500.00 per seat
    [B]:Ship $ 250.00 per seat
    ************************************************** ************************************************** *****
    Please enter your selection here:
    a
    ************************************************** ************************************************** ****
    Please take note of the following:

    If no upgrades are selected, travel will include economy seats and a stay in a standard room!

    Each trip can include only 1 upgrade selection!

    The 'All Upgraded Services' option is a special deal; cost for all options is regularly $250.00!
    ************************************************** ************************************************** ****
    Upgrade Menu:
    ************************************************** ************************************************** ****
    [A]:Transportation Upgrade $ 75.00 per seat
    [B]:Lodging Upgrade $ 125.00 per room
    [C]:Tour Upgrade $ 50.00
    [D]:All Upgrades $ 200.00
    [E]:No Upgrades $ 0.00
    ************************************************** ************************************************** *****
    Please enter your selection here:
    b
    ************************************************** *****************************
    Destination: Rome, Italy
    Lodging Cost: $ 500.00

    Transportation: Airplane
    Transportation Cost: $ 500.00

    Upgrade: Lodging Upgrade
    Upgrade Cost: $ 0.00 <------------ This should show 125.00
    Trip Cost: $ 0.00 <-------------This should show 1,125.00
    ************************************************** *******************************
    Destination Menu:
    ************************************************** ************************************************** ****
    [A]:Rome, Italy $ 500.00/5 day stay
    [B]:London, England $ 500.00/5 day stay
    [C]:Key West, Florida $ 500.00/5 day stay
    [Q] to Quit Program.
    ************************************************** ************************************************** *****
    Please enter your selection here:
    q
    ************************************************** ****************************************
    Final Report
    ************************************************** *****************************************
    Count of Rome, Italy <----------This should show 1
    Count of London, England
    Count of Key West, Florida

    Count of all trips: 1

    Total Trip Sales: $ 1000.00 <------This should show 1,125.00
    ************************************************** *****************************************

    It suppose to show the number of trips as well. So Rome, Italy would have 1 but its not showing up either.
    Last edited by tcw843; July 26th, 2019 at 10:04 AM. Reason: To show where problems are.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Trouble with outputs

    I assume that the print out that was posted is correct as I do not see any comments in it that describes what is wrong.
    For example I would expect to see this for a wrong value:
    Transportation: Airplane
    Transportation Cost: $ 500.00 <<<<< NO, this should be $750.00
    If you don't understand my answer, don't ignore it, ask a question.

  7. The Following User Says Thank You to Norm For This Useful Post:

    tcw843 (July 26th, 2019)

  8. #7
    Junior Member
    Join Date
    Jul 2019
    Location
    South Carolina
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Trouble with outputs

    ok hang on. i will edit the post.

    --- Update ---

    I edited my post with the output to show where the problems are. Thank you so much for your help.

  9. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Trouble with outputs

    Ok, lets work through the problems one by one:
    Upgrade Cost: $ 0.00 <------------ This should show 125.00
    What variable's value is shown there? Where in the code is that variable given a value?

    Add a print statement after every place in the code where that variable is given a value that prints a unique message and the value of the variable.
    The print out will show you:
    if the code is being executed
    and where the value that is printed came from
    If you don't understand my answer, don't ignore it, ask a question.

  10. #9
    Junior Member
    Join Date
    Jul 2019
    Location
    South Carolina
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Trouble with outputs

    UPGRADE_PRICE_LODGING is the variable and its declared with the class constant variables at the beginning.

    public static final double UPGRADE_PRICE_LODGING = 125.00;

    Can you show an example with adding a print statement?

  11. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Trouble with outputs

    A sample print statement:
       someVar = 123.4;   // give the variable a value
       System.out.println("1 someVar="+someVar);   // show what value was assigned here
     
       ...  then in another part of the code
       someVar = 23.5;   // give the variable another value
       System.out.println("2 someVar="+someVar);   // show what value was assigned here

    Every print statement should have a unique id. Above I used 1 and 2

    UPGRADE_PRICE_LODGING is the variable
    Is that the variable that is being printed for the line:
    Upgrade Cost: $ 0.00 <------------ This should show 125.00
    This is the statement that prints the above line:
    		System.out.printf("%-30s%1s%8.2f", "Upgrade Cost: ", "$" , borrowedUpgradeCost);
    That shows the value comes from the variable: borrowedUpgradeCost.
    Trace back to see where that variable is given a value.
    If you don't understand my answer, don't ignore it, ask a question.

  12. #11
    Junior Member
    Join Date
    Jul 2019
    Location
    South Carolina
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Trouble with outputs

    So everywhere there is UPGRADE_PRICE_LODGING, I should put this:

    else if (upgradeSelection == 'B')
    {
    upgradeName = UPGRADE_NAME_LODGING;
    upgradeCost = UPGRADE_PRICE_LODGING;
    UPGRADE_PRICE_LODGING = 125.00;
    System.out.println("The lodging upgrade is $125.00");
    }

    I have only written 4 programs before this one so I'm very new to Java so thank you for your patience.

  13. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Trouble with outputs

    everywhere there is UPGRADE_PRICE_LODGING, I should put this:
    Not necessarily. You want to see where the variable that is printed gets the value that is shown in the print out.
    What about for the case that the value in the variable is 0? Do any of the assignment statements assign it 0?
    If all the places where the variable is given a value also print out a message, the print out will show where the last value came from - it will be the last printed line before the report shows the value of 0.
    If NONE of the statements print a message showing the value was changed then you know the value in the variable was not changed from its initial default value which is 0 for most primitive variables.
    UPGRADE_PRICE_LODGING = 125.00;
    System.out.println("The lodging upgrade is $125.00");
    That print statement does not do what I suggested. It should show the name of the variable and the value in the variable:
    System.out.println("UPGRADE_PRICE_LODGING="+UPGRADE_PRICE_LODGING);

    However, UPGRADE_PRICE_LODGING is a constant and its value should never be changed. So what you posted does not make sense:
    UPGRADE_PRICE_LODGING = 125.00;  //<<<<<<<< NOT POSSIBLE to change a constant

    The variable is in this line: upgradeCost
       upgradeCost = UPGRADE_PRICE_LODGING;
    If you don't understand my answer, don't ignore it, ask a question.

  14. #13
    Junior Member
    Join Date
    Jul 2019
    Location
    South Carolina
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Trouble with outputs

    I know that upgradeCost is declared with the main method variables at the beginning:

    double upgradeCost = 0.0;

    As far as borrowedUpgradeCost, I believe its given a value here:

    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);

  15. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Trouble with outputs

    Ok if the variable: upgradeCost is the one with the problem, add a print statement after every place in the program where it is assigned a value.
    The print out will show you if and where it is being assigned a value. If nothing prints out, it is not getting a value otherwise the last line printed will show what value it has been assigned.


    borrowedUpgradeCost, I believe its given a value here:
    Where??? I don't see any statement that gives it a value in that posted code.
    If you don't understand my answer, don't ignore it, ask a question.

  16. #15
    Junior Member
    Join Date
    Jul 2019
    Location
    South Carolina
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Trouble with outputs

    So are you saying that

    upgradeCost = 0.0; should be upgradeCost = UPGRADE_PRICE_LODGING;?

    If that is the case, what happens if they choose another Upgrade option?

  17. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Trouble with outputs

    So are you saying that

    upgradeCost = 0.0; should be upgradeCost = UPGRADE_PRICE_LODGING;?
    NO NO NO.

    First you need to find out why the value that is printed is 0.
    THEN you work through the code to see why the value is 0 and not the desired code.
    If you don't understand my answer, don't ignore it, ask a question.

  18. The Following User Says Thank You to Norm For This Useful Post:

    tcw843 (July 26th, 2019)

  19. #17
    Member
    Join Date
    Jul 2019
    Posts
    36
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default Re: Trouble with outputs

    I found this:

    - here you forget brackets {} !! about line 150
    (without it upgradeCost=0)
    - and Calculations for Trip report must be before you print it with displayTripReport()
    so
    //--------------
    else { //!!
    upgradeName = UPGRADE_NAME_NONE;
    upgradeCost = UPGRADE_PRICE_NONE;
    } // !!

    //Calculations for Trip report - moved here !
    tripCost = lodgingCost + transportationCost + upgradeCost;

    //Output Trip report
    //----------------

    - part of displayFinalReport() has incorrect format description in printf() this is with correction

    //--------------
    System.out.printf("%-30s%1s%s%d\n", "Count of Rome, Italy" ,"","Trips: ", counterRome );
    System.out.printf("%-30s%1s%s%d\n", "Count of London, England" ,"","Trips: ", counterLondon);
    System.out.printf("%-30s%1s%s%d\n", "Count of Key West, Florida","","Trips: ", counterKeyWest);
    System.out.println("");

    System.out.printf("%-30s%d\n", "Count of all trips: ", tripCounter);
    System.out.println("");
    System.out.printf("%-30s%1s%8.2f\n", "Total Trip Sales: " , "$" , totalTripSales);
    //--------------

  20. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Trouble with outputs

    @zemiak Please read this: http://www.javaprogrammingforums.com...n-feeding.html

    Help the OP to learn how to find his problems. Don't do the work for him.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 1
    Last Post: July 29th, 2014, 04:34 PM
  2. Not getting the right outputs.
    By DarkestLord in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 15th, 2014, 03:42 PM
  3. Why do I get 0 in the outputs?
    By jean28 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 30th, 2012, 12:00 PM
  4. Code only outputs 1's
    By LoganC in forum What's Wrong With My Code?
    Replies: 7
    Last Post: September 27th, 2012, 09:26 PM
  5. LinkedList outputs ONLY last element
    By hexwind in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 30th, 2011, 04:57 AM