Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2016
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. Invoking System.currentTimeMillis() returns a long integer giving the elapsed time in milliseconds since midnight of January 1, 1970. The value returned is based on UTC time, which is 5 hours ahead of Central Daylight Time. Using the value returned by System.currentTimeMillis(), compute the current date and time, adjusting for Central Daylight Time and truncating to the second.
  2.  
  3. You can use any operators or any methods of the Math class, but do NOT call any methods that come with Java related to dates, times, calendars, etc. other than System.currentTimeMillis(). You may wish to use the long data type for all integer variables (otherwise be careful to use int only when you are sure the values will fit), and note that literal numeric values can be designated as long by appending an L, i.e., 5L is a long but 5 is an int. Your computations will need to take leap years into account. A leap year is any year that:
  4.  
  5. a. is divisible by 400, OR
  6.  
  7. b. is divisible by 4 but not divisible by 100
  8.  
  9. Display the current date and time in the following format.
  10.  
  11. Current date and time is September 29, 2016 at 10:10:01 am.
  12.  
  13. Next, using the fact that January 1, 1970 was a Thursday, compute the current day of the week. (Hint: For the computations, represent Sunday as 0, Monday as 1, …, Saturday as 6.) Do NOT use Zeller’s congruence (if you have heard of it) or call any methods that come with Java related to dates, times, calendars, etc. Then modify the above output format so that the new output format becomes:
  14.  
  15. Current date and time is Thursday, September 29, 2016 at 10:10:01 am.
  16.  
  17. Next, using the values you have computed for the current date and day of the week, compute the day of the week for the first day of the current month. Then write one or more loops that display a calendar for the current month in the following format with the leftmost column representing Sunday. (By coincidence, I ran my program on a Thursday and the first day of September was also a Thursday.) Do NOT call any methods that come with Java related to dates, times, calendars, etc.
  18.  
  19. Current date and time is Thursday, September 29, 2016 at 10:10:01 am.
  20.  
  21. 1 2 3
  22.  
  23. 4 5 6 7 8 9 10
  24.  
  25. 11 12 13 14 15 16 17
  26.  
  27. 18 19 20 21 22 23 24
  28.  
  29. 25 26 27 28 29 30
  30.  
  31. Next, add headers to the calendar for the name of the current month and the names of the days of the week. Add an asterisk before and after the current date on the calendar. The final output format should be (of course, the actual date and time you run the program will be different!):
  32.  
  33. Current date and time is Thursday, September 29, 2016 at 10:10:01 am.
  34.  
  35. September
  36.  
  37. ---------
  38.  
  39. Sun Mon Tue Wed Thu Fri Sat
  40.  
  41. 1 2 3
  42.  
  43. 4 5 6 7 8 9 10
  44.  
  45. 11 12 13 14 15 16 17
  46.  
  47. 18 19 20 21 22 23 24
  48.  
  49. 25 26 27 28 *29* 30
  50.  
  51. You are highly encouraged (but not required) to break up this program by writing “helper” methods, as described in Chapter 6!
  52.  
  53. Need Help?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement