*
The moose likes Beginning Java and the fly likes calculating number of days Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "calculating number of days" Watch "calculating number of days" New topic
Author

calculating number of days

Giles Harney
Greenhorn

Joined: Jun 22, 2004
Posts: 19
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
Dan Maples
Ranch Hand

Joined: Jun 21, 2004
Posts: 153
why can't you do: numberOfNights=totalNumberOfDays-1;
because if u were there 6 days that means u slept 5 nights, 7day=6nights, etc.


-Dan
Giles Harney
Greenhorn

Joined: Jun 22, 2004
Posts: 19
app has to compute total number of nights based on the dates entered by the user.
Darin Niard
Ranch Hand

Joined: Jun 08, 2004
Posts: 118
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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: calculating number of days