Jump to content

How to convert HH:MM:SS to just seconds

- - - - -

  • Please log in to reply
2 replies to this topic

#1
manzzaniita

manzzaniita

    Newbie

  • Members
  • Pip
  • 1 posts
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
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
What's the problem? You just need to read the user input.

#3
Sinipull

Sinipull

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 386 posts
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