CSE1020 Labtest 1D

Please read this part carefully

No collaboration is allowed during a labtest. Please refrain from speaking with other students during the test. If you have a question, please ask the teaching assistants or the instructor.

In your home directory you will find a copy of a solution to the ColourConvert problem from Lab 02. You may use pens/pencils and blank sheets of paper. No other aids are allowed.

You may use magic numbers instead of named constants for this test.

Your work will be evaluated based on its correctness and conformance to the style rules. Your code must compile to receive a passing grade.

Remember to save your work and submit your work at regular intervals during the test.

Test Problem

One way of writing the length of a song is to use a real number with 2 decimal places. For example, the number 4.38 would be interpreted as 4 minutes and 38 seconds.

Write a program called SongSeconds that reads one real number from the command line which represents an amount of time as described in the previous paragraph. Your program should output the amount of time as an integer quantity of seconds.

You might not know how to read real values from the command line; you can use the following line of code to read the amount of time from the command line:

double time = Double.parseDouble(args[0]);

Your program should output the amount of time as shown below:

java SongSeconds 3.00
3.0 is equal to
180 seconds

java SongSeconds 4.16
4.16 is equal to
256 seconds

java SongSeconds 6.23
6.23 is equal to
383 seconds

You may assume that the amount of time is always a "reasonable" amount (e.g., always positive or zero, not too large, has only 2 digits past the decimal that are less than 60).

Note that the "obvious" solution will often produce a result that is incorrect by 1 second; this is acceptable for this test. The off-by-1-second error occurs if you do not know how to round real numbers correctly in Java.

 

Submit

Submit your program using the command:

submit 1020 test01D SongSeconds.java

You may leave when you are finished.