File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

calculating number of days

 
Giles Harney
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Dan Maples
Ranch Hand
Posts: 153
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
app has to compute total number of nights based on the dates entered by the user.
 
Darin Niard
Ranch Hand
Posts: 118
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic