Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JOptionPane;
- public class Time2
- {
- public static void main(String[] args)
- {
- String Input;
- Input = JOptionPane.showInputDialog(null, "How many minutes did you work?");
- //convert Input to a integer.
- int numMinutes = Integer.parseInt(Input);
- //convert minutes to hours. Ints round down, so you get correct amount.
- int numHours = numMinutes/60;
- //Since numHours rounded down, this equation will give minutes left over.
- numMinutes = numMinutes-(60*numHours);
- // shows how many minutes there are on the job.
- System.out.print("Minutes on a job: ");
- System.out.println(numMinutes);
- // shows how many hours were worked on the job.
- System.out.print("Hours on a job: ");
- System.out.println(numHours);
- //Dialog output
- JOptionPane.showMessageDialog(null, "You worked " +Integer.toString(numHours)+" Hours and "+Integer.toString(numMinutes)+" minutes.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment