Countdown application for java
iam a newbie in java and i have a task at hand to make a simple application in java for countdown.
like for ex in that application if i enter the current date it should display how much time is left for christmas or a newyear or any religious occassion ...............
and it should display the result in the format like years/months/days/hours/minut开发者_如何学Goes and seconds........
plz help me for how to go with this...............
thanks in advance.
First start with a hello world tutorial. After that move on joda time library since it's much more usable than the standard Java time/date/calendar. If you need further help do not hesitate to post a question here.
How to go?
Let the user input the date, Calculate the difference from the inputted date to the occasions-dates and output them
The dates of the occassions you can put in a properties file that you read on launching the application
See Formatting dates for formatting
The task is pretty straightforward. You need solutions for the steps
- Capture user input (
Scanner
class, includes presenting a message to the user - Convert user input to a
Date
(includes rejecting invalid data) - Calculate the 'distance' to another date (like christmas)
- Print the result (convert the Date distance to a readable message)
1., 2. and 4. can be done in the main method, for 3. I'd implement a separate method. like private static Date getDistance(Date earlier, Date later)
精彩评论