Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package goods;
- import java.util.*;
- public class Main {
- static Scanner sc = new Scanner(System.in);
- static int seconds;
- static int minutes;
- static String print="";
- static int max;
- static Timer timer = new Timer();
- static String input;
- static Main timeboi = new Main();
- static TimerTask task = new TimerTask(){
- public void run(){
- seconds++;
- if(seconds == 60){
- seconds = 0;
- minutes++;
- }
- if(minutes < 10){
- print = "0";
- print+=minutes+":";
- if(seconds < 10){
- print+="0"+seconds;
- }
- else{
- print+=seconds;
- }
- }
- else{
- print = minutes+":";
- if(seconds < 10){
- print+="0"+seconds;
- }
- else{
- print+=seconds;
- }
- }
- System.out.printf("%02d:%02d",minutes,seconds);
- System.out.println();
- if (minutes+1 == max && seconds+1 == 60) {
- onesec();
- System.out.printf("%02d:%02d",minutes+1,0);
- timer.cancel();
- timer.purge();
- return;
- }
- }
- };
- public static void onesec(){
- try{
- Thread.sleep(1000);
- }
- catch(Exception e){}
- }
- public void start(){
- timer.scheduleAtFixedRate(task,1000,1000);
- }
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- System.out.println("Input \"soccer\" josh");
- input = sc.nextLine();
- if(input.equals("soccer")){
- System.out.println(soccer());
- }
- }
- public static String soccer(){
- max = 45; //this is the minute at which the timer will stop
- minutes = 43; //this is the current minute
- seconds = 55; //this is the current second
- timeboi.start();
- String lol = sc.nextLine();
- while(!lol.equals("end")){
- if(lol.equals("p")){
- timer.cancel();
- }
- else{
- timer = new Timer();
- task = new TimerTask(){
- public void run(){
- seconds++;
- if(seconds == 60){
- seconds = 0;
- minutes++;
- }
- if(minutes < 10){
- print = "0";
- print+=minutes+":";
- if(seconds < 10){
- print+="0"+seconds;
- }
- else{
- print+=seconds;
- }
- }
- else{
- print = minutes+":";
- if(seconds < 10){
- print+="0"+seconds;
- }
- else{
- print+=seconds;
- }
- }
- System.out.println(print);
- if (minutes+1 == max && seconds+1 == 60) {
- onesec();
- print = minutes+1+":00";
- System.out.println(print);
- timer.cancel();
- timer.purge();
- return;
- }
- }
- };
- timeboi.start();
- }
- lol = sc.nextLine();
- }
- return "Home Wins";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement