CSCI 161 - Lab 2: "Give Me a Second!"

Overview

This lab will have you developing a program that asks the user to input a time period as a number of seconds and in turn calculates the whole number of days, hours and minutes that are contained within the entered time period.

Refer to the "Output Format" below for an example of what your program must do.

The objectives of this lab are to reinforce and help teach:

Instructions

Following are the instructions and you should follow them carefully:

  1. Using Eclipse create a new Java Project and name it: Lab2
  2. As with all your labs, add a class of the same name, Lab2, and include in that class a main method.
  3. The main method and therefore your program should use an indefinite loop and within that loop:
    1. Prompt the user to enter a whole number of seconds or 0 to exit the program.
    2. Get input from the user as a single long integer.
    3. Check if 0 was entered and if so then...
    4. ...Print a departing message and terminate the loop and the program
    5. else if 0 not entered then....
    6. ...Print out the number of seconds entered and, ...
    7. ...Calculate and print out the total whole number of days contained within said seconds and, ...
    8. ...Calculate and print out the total whole number of hours contained within said seconds and, ...
    9. ...Calculate and print out the total whole number of minutes contained within said seconds and, ...
    10. ...Lastly, calculate and print out the days, hours, minutes and seconds within said seconds in the "digital clock" format of D:HH:MM:SS (see Output Format section, below). Note that calculating and outputting this line is probably the most difficult part of this program.
  4. Your program should output according to the "Output Format" below.
  5. The program must break down the task at hand into small operations, each one performed by a different method. You should be thinking of developing a diferent method for each computation and print, with each method accepting an integer input parameter (the number of seconds input) and printing that value out. For example:
                
    public static void printDays(int seconds) {
        // your code will calculate numbner of days in the seconds
        // passed in and then print that value out formatted with text
    }            
                
                
  6. Iteratively develop the lab (get one method working, test it, fix syntax errors, continue on to the next).
  7. When the lab is complete and working submit your Lab2.java file via AutoLab.

Things to Consider & Remember

  1. Utilize a commenting style like the one shown in class (here).
  2. Method names and variable names should have the proper camelCase.
  3. Use proper indentation for your curly braces, conditional statements, loops.
  4. You should be able to find some code to re-use (with some modifications required) in the last lecture code sample (here.)
  5. Your program should store the seconds entered by the user in a variable of the long data type.
  6. Your program should have many methods, ideally one method for each of the different feature steps about (approximately 8 in total for i. through x. above).
  7. Test with many different seconds values (a few digits, many digits, 0, ...).

Output Format

Following is an example of the desired output format:


Enter a number of seconds as a whole number or 0 to quit:  3600

Number of seconds entered is 3600 and that equates to:
	0 days
	1 hours
	60 minutes
	0:01:00:00 days, hours, minutes and seconds (D:HH:MM:SS:)

Enter a number of seconds as a whole number or 0 to quit:  123456

Number of seconds entered is 123456 and that equates to:
	1 days
	34 hours
	2057 minutes
	1:10:17:36 days, hours, minutes and seconds (D:HH:MM:SS:)
    
Enter a number of seconds as a whole number or enter 0 to exit:  723672

Number of seconds entered is 723672 and that equates to:
	8 days
	201 hours
	12061 minutes
	8:09:01:12 days, hours, minutes and seconds (D:HH:MM:SS:)    

Enter a number of seconds as a whole number or 0 to quit:  0

0 entered. Goodbye!
 
            

Deadline

This lab must be submitted to the instructor via AutoLab by 11:59:59pm on Monday September 18th