Question

(6%) You remembered currentime.java in class that was used to access Calendar.HOUR, Calendar.MINUTE etc. to display...

  1. (6%) You remembered currentime.java in class that was used to access Calendar.HOUR, Calendar.MINUTE etc. to display time like

The current time is 7:3:11

The current time is 7:3:12

The current time is 7:3:13

Enhance this program to display AM (morning) and PM as well. Run your program once in the morning and once in the afternoon to verify it works.

Can you enhance your program to display the current day and month as well?

Enhance the program to find the duration (say for example, how long it takes to run for loop 1000 times to run animation).

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Calendar;
public class ShowCurrentTime {

        static final String months[] = { "", "January", "February", "March", "April", "May", "June", "July", "August",
                        "September", "October", "November", "December" };

        public static void main(String[] args) {
                Calendar cal = Calendar.getInstance();

                String time = cal.get(Calendar.DAY_OF_MONTH) 
                                + " " + months[cal.get(Calendar.MONTH)]
                                + " " + cal.get(Calendar.HOUR) 
                                + ":" + cal.get(Calendar.MINUTE) 
                                + ":" + cal.get(Calendar.SECOND)
                                + " " + (cal.get(Calendar.AM_PM) == Calendar.AM ? "AM" : "PM");
                System.out.println(time);
        }

}


Please upvote, as i have given the exact answer as asked in question. Still in case of any issues in code, let me know in comments. Thanks!

Add a comment
Know the answer?
Add Answer to:
(6%) You remembered currentime.java in class that was used to access Calendar.HOUR, Calendar.MINUTE etc. to display...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVA 1. Create a MyTime class which is designed to contain objects representing times in 12-hour...

    JAVA 1. Create a MyTime class which is designed to contain objects representing times in 12-hour clock like 7:53am, 10:20pm, 12:00am (= midnight), 12:00pm (= noon). Provide a default constructor, a set method which is given a String (eg, “7:53am”), a getHours method, a getMinutes method and a boolean isAm method. Also provide a method for returning a string “morning”, “afternoon”, “evening” or “night” appropriate (in your opinion) to the time. Please see the NOTE below concerning input validation and...

  • For this project you will be writing up a simple Clock program to keep track of...

    For this project you will be writing up a simple Clock program to keep track of time. SimpleClock.java - contains your implementation of the SimpleClock class. You will need to provide the code for a constructor as well as the mutator methods set and tick and the accessor method toString. Look at the comments for each method to see how they should be implemented - the trickiest method is probably tick, which requires that you deal with the changing of...

  • 1. Create a MyTime class which is designed to contain objects representing times in 12-hour clock...

    1. Create a MyTime class which is designed to contain objects representing times in 12-hour clock format. Eg: 7:53am, 10:20pm, 12:00am (= midnight), 12:00pm (= noon). You can assume the user will enter times in the format given by the previous examples. Provide a default constructor, a set method which is given a String (eg: “7:53am”), a getHours method, a getMinutes method and a boolean isAm method. Also provide a method for returning a string “morning”, “afternoon”, “evening” or “night”...

  • Write a C++ program to display workers schedule for a company. To accomplish this (1) Write...

    Write a C++ program to display workers schedule for a company. To accomplish this (1) Write a struct Time with attributes (at least) : hours, minutes and seconds. Add other functions or attributes you need to get the job done (2) Write a class Schedule with attributes : Day of week, start_time, end_time and activity. Schedule should have at least (a) Display to display the schedule (b) Length to return the duration of the schedule (ie end_time - start_time), (c)...

  • Assume the memory display of the HCS12 shows 16 bytes starting at S0800 as follows SOBO0...

    Assume the memory display of the HCS12 shows 16 bytes starting at S0800 as follows SOBO0 80 53 05 28 36 89 00 FF FE 80 91 3E 77 AB 8F 7F Cavt the results of the following instructions SP S0805 pula A ?, SP SP S08OAL pula pshb A 7, SP -? SP S0805 pula A ? pulb B Idaa $O803 Idab $0804 aba A 7,8- SP $0805 psha pshb SP 7 Idx S0800 idab $0807 leax B.X X...

  • Step 1 Develop the following class: Class Name: Bag Access Modifier: public Instance variables Name: name...

    Step 1 Develop the following class: Class Name: Bag Access Modifier: public Instance variables Name: name Access modifier: private Data Type: String Name: currentWeight Access modifier: private Data Type: double Name: maximumWeight Access modifier: private Data Type: double Constructors Name: Bag Access modifier: public Parameters: none (default constructor) Task: sets the value of the instance variable name to the empty string sets the value of the instance variable currentWeight to 0.0 sets the value of the instance variable maximumWeight to...

  • System Time Calculation Objectives of this Lab: The objective of this assignment is to get used...

    System Time Calculation Objectives of this Lab: The objective of this assignment is to get used to the system time information in Linux. You will do that by writing a small program (in either C, C++ or Java) that will access system time information available from the Linux /proc directory. How to proceed with the Program: 1. Information in the /proc/uptime is available just as though the file were a regular text file. You may open the file, read out...

  • HI C PROGRAMMING COULD YOU,, Rewrite the program to have it display the time on the...

    HI C PROGRAMMING COULD YOU,, Rewrite the program to have it display the time on the second line of the display, using the HH:MM:SS format. Use the 24-hour format for the hours, in other words, have the time go from 00:00:00 to 23:59:59. #include<LiquidCrystal.h> LiquidCrystal LcdDriver(11, 9, 5, 6, 7, 8); int minutes = 27; //These global integers keep the value of the clock int sec = 10; int hr = 10; const long interval = 1000; //This interval is...

  • please follow the instruction ( very important ) 1912275-dt content-rid 43901523 1/courses/CSct A31. (25 pts) You...

    please follow the instruction ( very important ) 1912275-dt content-rid 43901523 1/courses/CSct A31. (25 pts) You must use a tor loop in the following program Write, compile, debug, and run a program that will use a for loop to do the following Some investments compound interest. This means that the interest is added onto the balance periodically during the year, and the next interest is calculated on this larger balance. This makes the actual return on investment actually greater than...

  • 1. Create a new class called ReversibleArray. 2. In the class header, add the code <T>...

    1. Create a new class called ReversibleArray. 2. In the class header, add the code <T> immediately to the right of the class name. 3. Give this class two private instance variables: T[] array and int count 4. Create a constructor which takes in one parameter of type T[] and assign that parameter's value into this.array. Set count as the length of the array. 5. Add a toString() method that outputs the array values in the format: elem0, elem1, elem2,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT