Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help with java H/W. I need a program that calculates hours, minutes, second

ID: 3861858 • Letter: N

Question

Need help with java H/W. I need a program that calculates hours, minutes, seconds up to one day. Only need to calculate seconds up to one day or less. And no need to input strings like the teacher said.

Thanks

Task 3: We now want the program to calculate hours, minutes, seconds up to one day You will (if) conditional statements and code blocks to create the program. (Utilize if/else or nested as necessary) Output Show number of seconds input and a conversion to Hours, minutes and remaining seconds. Have a print line for any input in seconds than 1 day Have an additional output if the user enters seconds as or less than 0 Attach Snipping photo of Source Code and Output Jackson 8:54 AM Today No need to input strings. No need to calculate days. Break code blocks into smaller segments. Only calculate hours or minutes if there are enough seconds to equal 1 hour or equal 1 minute

Explanation / Answer

SecondsToHoursMinsSecs.java

import java.util.Scanner;

public class SecondsToHoursMinsSecs {

   public static void main(String[] args) {
//Declaring variables
int fromseconds,hours,minutes,seconds,toSeconds;
  
//Scanner class Object is used to read the inputs entered by the user
Scanner sc=new Scanner(System.in);
  
while(true)
{
   //getting the number of seconds entered by the user
System.out.print(" Enter Total Number of Seconds :");
fromseconds=sc.nextInt();
if(fromseconds>=86400)
{
   System.out.println("** Invalid.No of secs Must be less than 1 day **");
   continue;
}
else
break;
}
  
  
  
  
//calling the method secondTime() by passing the seconds as arguments
secondTime(fromseconds);

   }
/*This method will converts the seconds to hours,minutes,seconds
* Params:total Seconds
* Return:String
*/
private static void secondTime(int totseconds) {
  
//Declaring variable
int secs=totseconds;
  
//calculating the number of hours
int hours=totseconds/3600;
totseconds=totseconds-(hours*3600);

//calculating the number of minutes
int minutes=totseconds/60;
totseconds=totseconds-(minutes*60);

//Calculating the number of seconds
int seconds=totseconds;

//displaying the total seconds to hours,minutes,seconds
System.out.println(secs+" Seconds corresponds to "+hours+" hours "+minutes+" minutes "+seconds+" seconds");
  
  
}
}

___________________

Output:


Enter Total Number of Seconds :10000
10000 Seconds corresponds to 2 hours 46 minutes 40 seconds

___________________

Output#2:


Enter Total Number of Seconds :89000
** Invalid.No of secs Must be less than 1 day **

Enter Total Number of Seconds :78678
78678 Seconds corresponds to 21 hours 51 minutes 18 seconds

_________________Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote