• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

calculating number of days

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello again. New homework assignment....
User is prompted one at a time to enter in the following;
-arrival month (1-12)
-arrival day (1-31)
-arrival year
-departure month (1-12)
-departure day (1-31)
-departure year
(assume valid data)

application displays arrival date, departure date, daily rate (a constant of $115.00), total price and number of nights.

�Create a class that defines a reservation. This class should contain instance variables for the arrival date, departure date, number of nights, and total price. It should also contain a constant initialized to the nightly rate of $115.00.
�This class should contain at least two constructors: a default one and one that accepts the arrival date and departure date. Within this constructor, the number of nights and total price should be set. This means that this class should contain two methods that set both these instance variables. This class should also override the toString method.
�Create a driver class that gets the user input, creates a reservation object, and displays it in a dialog box.

If I were to breakdown what needs to be done;

-User inputs data

-App calculates # of nights based on user data

-App calculates total price

-App displays results

My first road block is- how do I go about calculating # of nights?

Would this get done in a separate class (GregorianCalendar?) file or could I do this in the driver class?

Thanks,
-Giles
 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why can't you do: numberOfNights=totalNumberOfDays-1;
because if u were there 6 days that means u slept 5 nights, 7day=6nights, etc.
 
Giles Harney
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
app has to compute total number of nights based on the dates entered by the user.
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just do something like this.

Now you just need to write the method.

edit: I did it in 1 line because I am awesome
[ July 06, 2004: Message edited by: Darin Niard ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic