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 5 of 5

Thread: Need help with Hotel booking math.

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need help with Hotel booking math.

    Hello everyone I'm working on a project for java class and I'm not advanced enough to do anything fancy, I have the basics of the program but for some reason it never adds up right. Can anyone help me correct this issue? thanks. Also i changed the name of doubleroom to roomroom because I thought doubleroom was messing with the math but apparently not lol.

    import java.util.Scanner;
     
    class resort4
    {
    	public static void main (String[] args)
    	{
    		int staytype;										//create int, some with values, some get values later.
                    int roomtype;
    		int weekdayrate = 5;
    		int weekendrate = 20;
    		int holidayrate = 50;
    		int smokingroom = 40;
    		int handicaproom = 10;
    		int nonsmokingroom = 50;
                    int book1;
                    int book2;
                    int book3;
                    int keepgoing;
                    int keepgoing2;
                    int stayday;
                    int finalprice = 0;
                    int singleroom = 60;
                    int roomroom = 100;
                    int VIP = 500;
     
     
     
                   int smokingornot;													//find smokingornot based on user input
                   System.out.println("Smoking, Non-Smoking, or Handicap?\n 1 for Smoking"
                           + "\n 2 for Non-Smoking"
                           + "\n 3 for Handicap");
                   Scanner keyboard = new Scanner(System.in);
                   smokingornot = keyboard.nextInt();
     
     
     
                   //smoking booking
                   if (smokingornot == 1)														//smoking room conditions
                   {
                       if (smokingroom <= 0)
                           System.out.println("Smoking room unavailable, please try"			//out of smoking rooms
                                   + "again.");
                        else
                           System.out.println(smokingroom + " " + "Smoking rooms "
                                   + "available.");												//smoking rooms are still available
                         System.out.println("Would you like to continue?\n"
                                   + "1 for yes\n"
                                   + "2 for no");
                           book1 = keyboard.nextInt();					//move to next part of program if user has made no errors
     
                          if (book1 == 2)
                              System.out.println("Room not booked, please restart");
                            else
                               smokingroom--;											//removes a smokingroom from count
     
                    }
     
     
     
                   //non-smoking booking
                   if (smokingornot == 2)
                   {
                       if (nonsmokingroom <= 0)
                           System.out.println("Non-Smoking room unavailable, please"
                                   + " try again.");
                        else
                           System.out.println(nonsmokingroom + " " + "Non-Smoking "
                                   + "rooms available.");
                           System.out.println("Would you like to continue?\n"
                                   + "1 for yes\n"
                                   + "2 for no");
                           book2 = keyboard.nextInt();											//user input to continue
                            if (book2 == 2)
                              System.out.println("Room not booked, please restart.");
                            else
                               nonsmokingroom--;									//removes a non smoking room from count
                   }  
     
     
          //handicap booking
                   if (smokingornot == 3)
                   {
                       if (handicaproom <= 0)
                           System.out.println("No Handicap rooms available, please "
                                   + "try again.");
                       else
                           System.out.println(handicaproom + " " + "Handicap rooms "
                                   + "available.");
                           System.out.println("Would you like to continue?\n"
                                   + "1 for yes\n"
                                   + "2 for no");
                           book3 = keyboard.nextInt();											//gets userinput to continue
     
                          if (book3 == 2)
                              System.out.println("Room not booked, please restart.");
                            else
                               handicaproom--;									//removes a handicap room from count
                   }    
     
                   {
                    System.out.println("What type of room would you like?\n"
                            + "1 for Single\n"
                            + "2 for Double\n"
                            + "3 for VIP");
                    roomtype = keyboard.nextInt();										        //assigns input to roomtype
     
                    if (roomtype == 1)													//single room arrangements
                        System.out.println("Single room arrangements will be made.");
                            finalprice = finalprice + singleroom;
                        if (roomtype == 2)												        //doubleroom arrangements
                           System.out.println("Double room arrangements will be made.");
     
                            if (roomtype == 3)
    						   System.out.println("VIP room arrangements will be made.");
                                   finalprice = finalprice + VIP;
     
                  }
     
                  {
     
                   System.out.println("How many nights will the guest be staying?\n"
                           + "Enter a number 1, 2, 3, etc.");									//prompt for number of nights stayed at hotel
     
                   stayday = keyboard.nextInt();												//assigns stayday a value
     
     
     
               } 
     
                  System.out.println("What type of rates should we apply?\n"
                          + "1 for Weekday\n"
                          + "2 for Weekend\n"
                          + "3 for Holiday");
                  staytype = keyboard.nextInt();												//assigns staytype a value
     
                {  if (staytype == 1)
                       finalprice = finalprice + weekdayrate;									//adds weekday rates
     
                      if (staytype == 2)
                          finalprice = finalprice + weekendrate;	
    																        //adds weekend rates
                         else
                           finalprice = finalprice + holidayrate;								        //adds holiday rates
                }            
     
                {  if (roomtype == 2)
    					finalprice = finalprice + roomroom;					      //adds double room rate to final price if necessary
                }
     
     
    		        	finalprice = finalprice * stayday;							         //multiplies nights stayed to final price
     
     
     
            System.out.println("Your total is" + " " + finalprice);								//prints out final price
     
     
     
     
     
     
     
     
        }          
     
    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Need help with Hotel booking math.

    Define what "adding up right" would be. Show a sample run and describe how it should be different. Point to the code causing the problem, if possible.

  3. #3
    Junior Member
    Join Date
    Dec 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help with Hotel booking math.

    A single room, one night stay, with a week day rate should come out to be 65. For some reason it shows 615, I have no idea whats messing it up o.Ojavaprobs.jpg

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Need help with Hotel booking math.

    What are the numbers that should be added to get that total of 65? What variables are used in to do it?

    One problem I see in the code is there are NOT {}s to enclose the code following if statements. You should ALWAYS enclose the code following if statements and while/for loops to prevent confusion and errors.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Need help with Hotel booking math.

    A key to understanding how to fix code to help someone is being able to duplicate their results. That usually requires knowing the inputs they've used to arrive at their results and understanding why the results are incorrect. That's why I asked for a sample run that you didn't provide. You can usually copy and paste from the console the results of your run to provide the sample run I've asked for, and that would answer Norm's question.

Similar Threads

  1. Replies: 2
    Last Post: September 27th, 2013, 04:20 AM
  2. Please, help me out in calculating guest number of stay in a hotel
    By Motion in forum What's Wrong With My Code?
    Replies: 5
    Last Post: March 20th, 2013, 08:58 AM
  3. Design Pattern for Online booking
    By tcstcs in forum Java Theory & Questions
    Replies: 0
    Last Post: January 14th, 2013, 05:21 AM
  4. Hotel Booking form ??
    By dynamix24 in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: March 22nd, 2012, 09:35 AM