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

Java programming b. Write another method called inSeconds that takes as argument

ID: 3878305 • Letter: J

Question

Java programming

b. Write another method called inSeconds that takes as arguments three integers: hours, minutes and seconds, computes the exact time in seconds, then returns the total number of seconds and prints the following message to the screen:

<hours> hours, <minutes> minutes and <seconds> seconds corresponds to:

<totalseconds> seconds

c. Write a few tests (5) for the inSeconds method. At least one of your tests should use the return value and one should simply use the method as if it were a void method.

Explanation / Answer

import java.util.*;
import java.lang.*;

class ConvertAllToSeconds
{  
public static int inSeconds(int hour, int min, int seconds){
  
if(seconds<=60){
return ((hour*60*60)+(min*60)+seconds);
}
else{
System.out.println("Seconds should less than 60 ");
return 0;
}
}
public static void main(String args[])
{
  System.out.println("Total in seconds "+inSeconds(12,25,54));
}
}

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