Design a class named StopWatch. The class contains: ?The private data fields startTime and endTime with get methods. ?A constructor that initializes startTime with the current time. ?A method named start() that resets the startTime to the current time. ? A method named stop() that sets the endTime to the current time. ?A method named getElapsedTime() that returns the elapsed time for the stop watch in milliseconds. Draw the UML diagram for the class, and then implement the class. This can be done in Word, or you may use any drawing tool that you like. Submit your diagram in as a PDF, or image file to Blackboard. Write a test program that measures the execution time of adding numbers from 1 to 1,000,000. Your output from the test program should look something like this: The loop time is 90 milliseconds. The number may be somewhat different depending on your computer. This is also submitted to Blackboard.
Added by Jacob C.
Close
Step 1
Identify the class name: StopWatch Show more…
Show all steps
Your feedback will help us improve your experience
Jennifer Hudspeth and 56 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
(Stopwatch) Design a class named StopWatch. The class contains: ? The private data fields startTime and endTime with get methods. ? A constructor that initializes startTime with the current time. ? A method named start() that resets the startTime to the current time. ? A method named stop() that sets the endTime to the current time. ? A method named getElapsedTime() that returns the elapsed time for the stop watch in milliseconds. Draw the UML diagram for the class, and then implement the class. Write a test program that measures the execution time of adding numbers from 1 to 1,000,000.
(The Time class) Design a class named Time. The class contains: ? The private data fields hour, minute, and second that represent a time. ? A constructor that constructs a Time object that initializes hour, minute, and second using the current time. ? The get methods for the data fields hour, minute, and second, respectively. ? A method named setTime(elapseTime) that sets a new time for the object using the elapsed time in seconds. For example, if the elapsed time is 555550 seconds, the hour is 10, the minute is 19, and the second is 12. Draw the UML diagram for the class, and then implement the class. Write a test program that creates a Time object and displays its hour, minute, and second. Your program then prompts the user to enter an elapsed time, sets its elapsed time in the Time object, and displays its hour, minute, and second. Here is a sample run: Current time is 12:41:6 Enter the elapsed time: 55550505 The hour:minute:second for the elapsed time is 22:41:45
(Tkinter: a group of clocks) Write a program that displays four clocks, as shown in Figure 12.24.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD