Advertisement
Guest User

timerforjosh

a guest
Jan 14th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. package goods;
  2. import java.util.*;
  3.  
  4. public class Main {
  5. static Scanner sc = new Scanner(System.in);
  6. static int seconds;
  7. static int minutes;
  8. static String print="";
  9. static int max;
  10. static Timer timer = new Timer();
  11. static String input;
  12. static Main timeboi = new Main();
  13. static TimerTask task = new TimerTask(){
  14. public void run(){
  15. seconds++;
  16.  
  17. if(seconds == 60){
  18. seconds = 0;
  19. minutes++;
  20. }
  21. if(minutes < 10){
  22. print = "0";
  23. print+=minutes+":";
  24. if(seconds < 10){
  25. print+="0"+seconds;
  26. }
  27. else{
  28. print+=seconds;
  29. }
  30. }
  31. else{
  32. print = minutes+":";
  33. if(seconds < 10){
  34. print+="0"+seconds;
  35. }
  36. else{
  37. print+=seconds;
  38. }
  39. }
  40. System.out.printf("%02d:%02d",minutes,seconds);
  41. System.out.println();
  42. if (minutes+1 == max && seconds+1 == 60) {
  43. onesec();
  44. System.out.printf("%02d:%02d",minutes+1,0);
  45. timer.cancel();
  46. timer.purge();
  47. return;
  48. }
  49. }
  50. };
  51. public static void onesec(){
  52. try{
  53. Thread.sleep(1000);
  54. }
  55. catch(Exception e){}
  56. }
  57. public void start(){
  58. timer.scheduleAtFixedRate(task,1000,1000);
  59. }
  60. public static void main(String[] args) {
  61. // TODO Auto-generated method stub
  62.  
  63. System.out.println("Input \"soccer\" josh");
  64. input = sc.nextLine();
  65. if(input.equals("soccer")){
  66. System.out.println(soccer());
  67. }
  68. }
  69. public static String soccer(){
  70. max = 45; //this is the minute at which the timer will stop
  71. minutes = 43; //this is the current minute
  72. seconds = 55; //this is the current second
  73. timeboi.start();
  74. String lol = sc.nextLine();
  75. while(!lol.equals("end")){
  76. if(lol.equals("p")){
  77. timer.cancel();
  78. }
  79. else{
  80. timer = new Timer();
  81. task = new TimerTask(){
  82. public void run(){
  83. seconds++;
  84. if(seconds == 60){
  85. seconds = 0;
  86. minutes++;
  87. }
  88. if(minutes < 10){
  89. print = "0";
  90. print+=minutes+":";
  91. if(seconds < 10){
  92. print+="0"+seconds;
  93. }
  94. else{
  95. print+=seconds;
  96. }
  97. }
  98. else{
  99. print = minutes+":";
  100. if(seconds < 10){
  101. print+="0"+seconds;
  102. }
  103. else{
  104. print+=seconds;
  105. }
  106. }
  107. System.out.println(print);
  108. if (minutes+1 == max && seconds+1 == 60) {
  109. onesec();
  110. print = minutes+1+":00";
  111. System.out.println(print);
  112. timer.cancel();
  113. timer.purge();
  114. return;
  115. }
  116. }
  117. };
  118. timeboi.start();
  119. }
  120. lol = sc.nextLine();
  121. }
  122. return "Home Wins";
  123. }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement