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

Time Calculator (C#) There are 60 seconds in a minute. If the number of seconds

ID: 3593711 • Letter: T

Question

Time Calculator (C#)

There are 60 seconds in a minute. If the number of seconds entered by the user is greater than or equal to 60, the program should display the number of minutes in that many seconds.

There are 3,600 seconds in an hour. If the number of seconds entered by the user is greater than or equal to 3600, the program should display the number of hours in that many seconds

There are 86,400 seconds in a day. If the number of seconds entered by the user is greater than or equal to 86400, program should display the number of days in that many seconds.

Explanation / Answer

import javax.swing.JOptionPane;
import java.util.Scanner;

public class CalculateTime
{
public static void main(String [] args)
{



String input; // declaration of variable
double seconds, minToCalculate, hrsToCalculate, DaysToCalculate;
final double secdsPerMin = 60;
final double secdsPerHr = 3600;
final double secdsPrDay = 86400;

input = JOptionPane.showInputDialog("Please enter seconds:");
seconds = Double.parseDouble(input);

if (seconds < secdsPerMin )
{
JOptionPane.showMessageDialog(null, seconds + " seconds (conversion was'nt made)");
}

else if (seconds >= secdsPerMin && seconds < secdsPerHr )
{
minToCalculate = seconds/secdsPerMin;
JOptionPane.showMessageDialog(null, seconds + " seconds equals: " + minToCalculate + " minutes");
}

else if (seconds >= secdsPerHr && seconds < secdsPrDay)
{
hrsToCalculate = seconds/secdsPerHr;
JOptionPane.showMessageDialog(null, seconds + " seconds equals: " + hrsToCalculate + " hours");
}

else if (seconds >= secdsPrDay)
{
DaysToCalculate = seconds/secdsPrDay;
JOptionPane.showMessageDialog(null, seconds + " seconds equals: " + DaysToCalculate + " days");
}

}
}

Happy coding Have a great day.

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