Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Sleep
- {
- public static void main (String [] args) throws InterruptedException
- {
- Scanner console = new Scanner (System.in);
- int second = 0, minute = 0, hour = 0;
- int hourToSeconds, minuteToSeconds, totalOfAllSeconds;
- int counter = 0, beep = 0, alertOnFinish = 0, numberOfBeeps = 0;
- System.out.print ("Enter how long you want the timer to run each separated by a space. \n (hours minutes seconds) ");
- hour = console.nextInt();
- minute = console.nextInt();
- second = console.nextInt();
- hourToSeconds = (hour * 3600);
- minuteToSeconds = (minute * 60);
- totalOfAllSeconds = (hourToSeconds + minuteToSeconds + second);
- System.out.print ("Do you want the program to alert you with sound when it has finished? \n1 for yes and 2 for no. ");
- alertOnFinish = console.nextInt();
- if (alertOnFinish == 1)
- {
- System.out.println ("How many beeps would you like?");
- numberOfBeeps = console.nextInt();
- }
- while (counter < totalOfAllSeconds)
- {
- counter++;
- Thread.sleep(1000);
- }
- if (alertOnFinish == 1)
- {
- while (beep < numberOfBeeps)
- {
- Thread.sleep(1000);
- System.out.println ("\007");
- beep++;
- }
- System.out.println ("The timer has alerted you that it has finished.");
- }
- if (alertOnFinish != 1)
- {
- System.out.println ("The timer has finished.");
- }
- }
- }
Add Comment
Please, Sign In to add comment