java programming

1. Time Calculator Write a program that asks the user to enter a number of seconds. • 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 3,600, 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 86,400, the program should display the number of days in that many seconds.

1. 👍 0
2. 👎 0
3. 👁 199
1. ergs

1. 👍 0
2. 👎 0
posted by ergs
2. //import java.util.Scanner;
import javax.swing.JOptionPane;

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

//variable declarations

String input;
double seconds, minutesCalculated, hoursCalculated, daysCalculated;
final double secondsPerMinute = 60;
final double secondsPerHour = 3600;
final double secondsPerDay = 86400;

input = JOptionPane.showInputDialog("Enter the seconds:");

if (seconds < secondsPerMinute)
{
JOptionPane.showMessageDialog(null, seconds + " seconds (no conversion was made)");
}

else if (seconds >= secondsPerMinute && seconds < secondsPerHour )
{
minutesCalculated = seconds/secondsPerMinute;
JOptionPane.showMessageDialog(null, seconds + " seconds equals: " + minutesCalculated + " minutes");
}

else if (seconds >= secondsPerHour && seconds < secondsPerDay)
{
hoursCalculated = seconds/secondsPerHour;
JOptionPane.showMessageDialog(null, seconds + " seconds equals: " + hoursCalculated + " hours");
}

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

}

1. 👍 0
2. 👎 0

Similar Questions

1. intro to computer programming

Write a program that asks the user to enter the number of packages purchased. The program should then display the amount of the discount (if any) and the total amount of the purchase after the discount. Your program should use a

asked by Anonymous on October 26, 2015
2. java programming

Your boss at Ruritania Weather Center (RWC) has asked you to write a small program for center. The specification are as follows: a. the program asks a user to enter a number between 1 and 12 inclusive representing the months

asked by lebo on October 21, 2014
3. computer

Create a new project Lab05e, and write a program that asks the user to enter a line. The program must find the one or more words between quotation marks (“”) characters and print them as follows: Please enter a line: She

asked by eric on October 29, 2010
4. Programming

Write a pseudocode program that asks the user for an integer between 1 and 12. The program is to calculate the times table for that number. So for example, if the user enters a 2, then the program has to calculate 2x1 and display

asked by Darlene on August 17, 2011
5. Programming in c++

Write a program in c++ that inputs a number [1-12] from the user and displays the month. it also asks the user whether he wants to input another number or not, if the user inputs 1 then it again inputs number, if user inputs 0

asked by osama qaiser on December 16, 2012
6. Intro to Software Developement

How do I make a Raptor flowchart program that asks the user to enter a 10 character telephone number in the format XXX-XXX-XXXX, that makes the program display the telephone number with any alphabetic characters that appeared in

asked by Marquita on April 29, 2016
7. Computers

How do I make a Raptor flowchart program that asks the user to enter a 10 character telephone number in the format XXX-XXX-XXXX, that makes the program display the telephone number with any alphabetic characters that appeared in

asked by Marquita on April 29, 2016
8. Programming in c++

Draw a flow-chart and Write a program that asks the user to enter students grades. The program should stop reading when the use enters ‘*’. In addition, your program should print the number of students got each grade. The

asked by alhan on April 15, 2013
9. l;k

Write a program that asks the user to enter the student’s name (first and last), and his/her first exam grade of three students, and then display them in a neat format. After that the program will find the average of the three

asked by ayham on October 24, 2011
10. java programming

the learner is asked to write a program using java with user input that caculate and displays, the number of months it will take the user to save an amount of money. the user must enter the

asked by omar on November 17, 2015

More Similar Questions