/**
TimeCalc.java
Craig Persiko
CS 111A Solution to Programming Lab 1
Modified version of program taken from
Tony Gaddis' Starting Out with Java,
from Control Structures to Objects
Chapter 3
Programming Challenge 6: Time Calculator
*/
import java.util.Scanner;
public class TimeCalc
{
public static void main(String[] args)
{
Scanner scan = new Scanner (System.in);
double seconds; // The number of seconds
// Get the number of seconds.
System.out.println("Enter the number of seconds");
seconds = scan.nextDouble();
// If seconds is less than 60, that's all we have... just seconds.
if (seconds < 60)
{
System.out.println("That's less than a minute, an hour, or a day.");
}
// Display the number of minutes, if any.
if (seconds >= 60)
{
System.out.println("There are " + (seconds / 60) +
" minutes in " + seconds + " seconds.");
}
// Display the number of hours, if any.
if (seconds >= 3600)
{
System.out.println("There are " + (seconds / 3600) +
" hours in " + seconds + " seconds.");
}
// Display the number of days, if any.
if (seconds >= 86400)
{
System.out.println("There are " + (seconds / 86400) +
" days in " + seconds + " seconds.");
}
}
}
/* Sample Output:
-bash-3.2$ java TimeCalc
Enter the number of seconds
30
That's less than a minute, an hour, or a day.
-bash-3.2$ java TimeCalc
Enter the number of seconds
90
There are 1.5 minutes in 90.0 seconds.
-bash-3.2$ java TimeCalc
Enter the number of seconds
4000
There are 66.66666666666667 minutes in 4000.0 seconds.
There are 1.1111111111111112 hours in 4000.0 seconds.
-bash-3.2$ java TimeCalc
Enter the number of seconds
90000
There are 1500.0 minutes in 90000.0 seconds.
There are 25.0 hours in 90000.0 seconds.
There are 1.0416666666666667 days in 90000.0 seconds.
-bash-3.2$
*/
syntax highlighted by Code2HTML, v. 0.9