This week's book giveaway is in the Testing forum.We're giving away four copies of The Way of the Web Tester: A Beginner's Guide to Automating Tests and have Jonathan Rasmusson on-line!See this thread for details.
Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

# calculating number of days

Giles Harney
Greenhorn
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
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.

Giles Harney
Greenhorn
Posts: 19
app has to compute total number of nights based on the dates entered by the user.

Darin Niard
Ranch Hand
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 ]