Guest User

Untitled

a guest
Jan 20th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Sleep
  4. {
  5.     public static void main (String [] args) throws InterruptedException
  6.     {
  7.         Scanner console = new Scanner (System.in);
  8.         int second = 0, minute = 0, hour = 0;
  9.         int hourToSeconds, minuteToSeconds, totalOfAllSeconds;
  10.         int counter = 0, beep = 0, alertOnFinish = 0, numberOfBeeps = 0;
  11.  
  12.         System.out.print ("Enter how long you want the timer to run each separated by a space. \n (hours minutes seconds) ");
  13.         hour = console.nextInt();
  14.         minute = console.nextInt();
  15.         second = console.nextInt();
  16.  
  17.         hourToSeconds = (hour * 3600);
  18.         minuteToSeconds = (minute * 60);
  19.         totalOfAllSeconds = (hourToSeconds + minuteToSeconds + second);
  20.  
  21.         System.out.print ("Do you want the program to alert you with sound when it has finished? \n1 for yes and 2 for no. ");
  22.  
  23.         alertOnFinish = console.nextInt();
  24.  
  25.         if (alertOnFinish == 1)
  26.         {
  27.             System.out.println ("How many beeps would you like?");
  28.             numberOfBeeps = console.nextInt();
  29.         }
  30.  
  31.         while (counter < totalOfAllSeconds)
  32.         {
  33.             counter++;
  34.             Thread.sleep(1000);
  35.         }
  36.  
  37.         if (alertOnFinish == 1)
  38.         {
  39.  
  40.             while (beep < numberOfBeeps)
  41.             {
  42.                 Thread.sleep(1000);
  43.                 System.out.println ("\007");
  44.                 beep++;
  45.             }
  46.  
  47.             System.out.println ("The timer has alerted you that it has finished.");
  48.         }
  49.  
  50.         if (alertOnFinish != 1)
  51.         {
  52.             System.out.println ("The timer has finished.");
  53.         }
  54.     }
  55. }
Add Comment
Please, Sign In to add comment