Here is the problem:
Write a Java program the prompts the user to input the elapsed time for an event in hours,minutes, and seconds. The program then outputs the elapsed time in seconds.
And here is what I got so far...
/
/*
Your step by step algorithm solution presented in pseudo-code goes here
1.Prompt user to input the elapsed time for an event in hours, minutes, and seconds
2.Get the time from the user
3.Input hours
4.Input minutes
5.Input seconds
3.Compute total seconds from hours = hours * 3600
4.Compute total seconds from minutes = minutes * 60
5.Compute total elapsed time = total seconds from hours + total seconds from minutes + seconds
6.Print elapsed time
7. Quit
*/
//Your actual Java Language implementation will follow here
import java.util.*;
public class Problem12
{
static Scanner console = new Scanner(System.in);
public static void main(String[] agrs)
{
// Data Declaration
int TotalElapsedTime;
int hours;
int minutes;
int seconds;
// Algorithm Implementation
System.out.print("Please enter the time in hours,minutes, and seconds --> ");
TotalElapsedTime = console.nextInt();
TotalElapsedTime = (hours * 3600) + (minutes * 60) + seconds;
System.out.println("Total elapsed time was:" + TotalElapsedTime);
}
}
Help please!!
2 replies to this topic
#1
Posted 25 January 2012 - 07:13 PM
|
|
|
#2
Posted 26 January 2012 - 12:24 AM
What's the problem? You just need to read the user input.
#3
Posted 26 January 2012 - 01:54 AM
You are asking the user to input an integer. You need to input a String in format hh:mm:ss. Then you need to split it from the colons and convert it to separate integers.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









