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

Thread: Please, help me out in calculating guest number of stay in a hotel

  1. #1
    Junior Member Motion's Avatar
    Join Date
    Jul 2012
    Posts
    21
    My Mood
    Happy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Please, help me out in calculating guest number of stay in a hotel

    I' working on a hotel management software and wants the numbers of days a present guest have stayed to show on a JTable on
    clicking a Button that is meant to select all guestid and NoOfDays in a table I named InGuests .e.g "SELECT GUESTID, NOOFDAYS
    FROM INGUESTS".
    I retrieved with ResultSet and used while loop to iterate on the result and compare the current date with the date checked in.
    I also made it to increement or void where necessary and finally update the NoOfDays column in the InGuests Table. but it seems not tot be working. Please help me
    If you don't understand...kindly ask me to explain more.

    Thanks Gurus in da house



     
     
    // get the current system date 
                         Date dated = new Date();
     
    //returns only the date
                        String date = DateFormat.getDateInstance().format(dated);
     
                        String mo = "";
                        String da = "";
                        String yy = "";
     
                        StringTokenizer tok = new StringTokenizer(date, " ");
                        if(date != null)
                        {
                            mo = tok.nextToken().toString();
                            da = tok.nextToken().toString();
                            yy = tok.nextToken().toString();
     
     
     
                        }
     
                        String day = "";
                        String month = "";
                        String year = "";
     
                        if(mo.equalsIgnoreCase("Jan"))
                        {
                            month = "01";
                        }
                        else if(mo.equalsIgnoreCase("Feb"))
                        {
                            month = "02";
                        }
                        else if(mo.equalsIgnoreCase("Mar"))
                        {
                            month = "03";
                        }
                        else if(mo.startsWith("Apr"))
                        {
                            month = "04";
                        }
                        else if(mo.equalsIgnoreCase("May"))
                        {
                            month = "05";
                        }
                        else if(mo.equalsIgnoreCase("Jun"))
                        {
                            month = "06";
                        }
                        else if(mo.equalsIgnoreCase("Jul"))
                        {
                            month = "07";
                        }
                        else if(mo.startsWith("Aug"))
                        {
                            month = "08";
                        }
                        else if(mo.startsWith("Sept"))
                        {
                            month = "09";
                        }
                        else if(mo.equalsIgnoreCase("Oct"))
                        {
                            month = "10";
                        }
                        else if(mo.equalsIgnoreCase("Nov"))
                        {
                            month = "11";
                        }
                        else if(mo.equalsIgnoreCase("Dec"))
                        {
                            month = "12";
                        }
                        String currDate = da.substring(0,2)+"/"+month+"/"+yy;
     
                        StringTokenizer currDateToken = new StringTokenizer(currDate, "/");
     
                        if(currDate != null)
                        {
                            toDay = currDateToken.nextToken().toString();
                            todayMonth = currDateToken.nextToken().toString();
                             todayYear = currDateToken.nextToken().toString();
     
     
     
                        }
     
                         int curr = 0;
                        int inDate = Integer.parseInt(InDa);
                        int toDate = Integer.parseInt(toDay);
     
                        if(toDate != inDate)
                        {
                            NoOfDays++;
     
                            NoOfDays = curr;
     
                        }
                        else if(inDate == toDate)
                        {
                            NoOfDays = curr;
     
                        }
                         try
                        {
                        String updateDays = "update inguests set Noofdays = '"+NoOfDays+"' where guestid = '"+id+"'";
     
                        int up = Database.exec(updateDays);
     
     
                        if(up >= 1)
                        {
                            initLabel.setText("InGuests Initialized!");
     
                        }
                        else
                        {
                            initLabel.setText("InGuests not Initialized!");
     
                        } 
                        }
                        catch(Exception ex)
                        {
                            ex.printStackTrace();
                        }


  2. #2
    Member Chris.Brown.SPE's Avatar
    Join Date
    May 2008
    Location
    Fort Wayne, Indiana
    Posts
    190
    Thanks
    1
    Thanked 31 Times in 31 Posts

    Default Re: Please, help me out in calculating guest number of stay in a hotel

    I'm not sure where to start. I cant really hammer down what is going on as it seems there is code missing. Can you post the whole class so i can see where all variables are being initialized? Maybe throw in some comments on different sections so we know what you think it should be doing?

  3. #3
    Junior Member Motion's Avatar
    Join Date
    Jul 2012
    Posts
    21
    My Mood
    Happy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please, help me out in calculating guest number of stay in a hotel

    Thanks for your concern bro.

    The whole project seem ambiguous, but in break down:
    I want to read a date stored in a database and compare it with the current date
    if the two matches nothing will happen, but if it doesn't. No of Stay will increment and update the databse.
    Thats the scope bro
    Thanks

  4. #4
    Member Chris.Brown.SPE's Avatar
    Join Date
    May 2008
    Location
    Fort Wayne, Indiana
    Posts
    190
    Thanks
    1
    Thanked 31 Times in 31 Posts

    Default Re: Please, help me out in calculating guest number of stay in a hotel

    The imediate problem i'm seeing is that you're setting the NoOfStay to current after you increment it. Basically overwritting your increment.

                        if(toDate != inDate)
                        {
                            NoOfDays++;//increment
     
                            NoOfDays = curr;//overwrite with current
     
                        }
                        else if(inDate == toDate)
                        {
                            NoOfDays = curr;//set to current, the same thing you are doing above
     
                        }

  5. #5
    Junior Member Motion's Avatar
    Join Date
    Jul 2012
    Posts
    21
    My Mood
    Happy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please, help me out in calculating guest number of stay in a hotel

    Curr is a int variable i created to pass the value of NoOdDays with which I will write to DB

    Inside the 'if' part: when today's date is not equals to Indate, it should increment and parse the value to 'Curr'.
    the 'else' part; if they are the same, it sholud parse the value to 'Curr' while will then update thet DB.

    Please correct me.., if I'm wrong.
    thanks

  6. #6
    Member Chris.Brown.SPE's Avatar
    Join Date
    May 2008
    Location
    Fort Wayne, Indiana
    Posts
    190
    Thanks
    1
    Thanked 31 Times in 31 Posts

    Default Re: Please, help me out in calculating guest number of stay in a hotel

    Let me set some values to these variables for my example.

    NoOfDays = 2;
    curr = 5;

    In your if statement, NoOfDays will increment to 3 then be set to 5.
    In your else statement, NoOfDays will be set to 5.
    It will always be the same...always.

Similar Threads

  1. how to stay focus learning java?
    By malayo in forum Totally Off Topic
    Replies: 3
    Last Post: October 27th, 2012, 11:10 PM
  2. Replies: 1
    Last Post: September 23rd, 2012, 01:02 PM
  3. Hotel Booking form ??
    By dynamix24 in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: March 22nd, 2012, 09:35 AM
  4. JFrame declared as setAlwaysOnTop doesn't stay on top during slide show
    By ravindra_appikatla in forum AWT / Java Swing
    Replies: 1
    Last Post: March 30th, 2010, 09:08 AM