Learning Objectives
After completion of this lab, you should be able to
class to format double values as a stringAll labs in CS 110 will be done as pair programming teams. Your partner for today's lab is listed in the table below:
| Team 1 Aguilar Jr, Jaime Field, Sarah |
Team 2 Amezcua Gutierrez, Edson Hansen, Mitchell |
Team 3 Baird, Owen Hastings, Jake |
Team 4 Berman, Jake Hogan, Martin |
Team 5 Coudriet, Blake Ling, Nathan |
| Team 6 Erickson, Joel Nash, Chris |
Team 7 Goeke, Max Olivares, Scott |
Team 8 Harris, Alexander Shearer, Stetson |
Team 9 Heflick, Liz Wagster, Nathan |
Team 10 McCauley, Rylee Smith, Stephanie |
| Team 11 Millard, Ryan Akana, Chris |
Team 12 Olden, Greg Awan, Samara |
Team 13 Quayle, Weston Barrett Wright, Matthew |
Team 14 Straub-Walden, Andy Bloom, Thomas |
Team 15 Williamson, Sarah Cuddington, Chris |
| Fill in: Millard, Mike | ||||
Note: Partners will change every week.
You may wish to review basic pair programming guidelines before you begin.
You should change roles every 10 to 15 minutes.
You will write a Java class called Seconds that converts a time value represented in seconds (double) to its equivalent time value as a String
For example, the time 69.752 (in seconds) would be represented as the String "1:9.752" or 1 minute, 9 seconds, and 752 milliseconds (in minutes:seconds.milliseconds).
Begin by developing test cases for this program.
| Time (in seconds) | Time | ||
|---|---|---|---|
| minutes | seconds | milliseconds | |
| 69.752 | 1 | 9 | 752 |
| 336.219 | 5 | 36 | 219 |
| 542.200 | |||
| 226.987 | |||
| 85.333 | |||
Write your calculated test case values in the Lab assignment sheet. You will turn in this sheet at the end of lab for credit.
In the test cases, time (in seconds) is represented as a double value. The part to the left of the decimal represents the total seconds, the part to the right of the decimal represents the milliseconds.
Converting a double to an integer value in Java is done with the cast operator. For example, to convert the double variable d to the integer i, we could write
In this case, i would be set to 336
To get at the decimal part of 336.219, we could use a combination of multiplication, casting, and the modulus operator
In this case, fractionalPart would equal 219
class to format double values as a stringclass Seconds and save as Seconds.javaformat(), that returns a String formatted as minutes:seconds.millisecondsA short main method will be used for testing purposes.
TestSeconds.javaSample Session
Enter a time in seconds: 336.219
5:36.219
Once your class is tested and determined to be working correctly, we will use it to format time (as a double) into a strings to display in a graphical user interface (GUI) Windows application acting as a stopwatch.
U:\labs\lab6 folder the following two Java files
StopWatchGui class and confirm that the stopwatch is working correctly
TimeFormat class code
Java programs need to be thoroughly tested before being sold or released to the public.
The best testers are usually independent testers, or those who did not write the source code. It has been shown that developer of the source code overlook many bugs while testing because they are not thorough or they make false assumptions about using the program that independent testers often catch as errors.
Even though the user interface to the stopwatch program is very simple, it has subtle errors.
Examine the code that you downloaded and added to your lab6 folder. StopWatchGui.java contains the code that creates the graphical user interface that displays as a window application.
A problem occurs with the stopwatch program when the user clicks on the stop button without clicking the start button first. (Try it if you did not discover this problem in the previous activity)
One way to fix the problem (as a programmer) is to design the user interface to initially disable the Stop button to prevent the user for clicking it before they clicked the Start button. To disable or enable a button, use the button's setEnabled() method, passing a true or false value as the method argument.
StopWatchGui.java code and find where the Stop button is created.StopWatchGui.java code find where the method called when the user clicks on the Start button
lab folder to the partner's USB thumb drive (or email it to them if they do not have a thumb drive).U:\labs\lab6 folder and turn in the Lab 6 assignment sheet at the start of the next lab
You are allowed to drop one lab grade for the entire quarter.