Skip to content

Commit

Permalink
Now can pass '-t (duration time)' argument in run command
Browse files Browse the repository at this point in the history
  • Loading branch information
Xuitty committed May 12, 2023
1 parent d6bbc2c commit 1b9700c
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions src/com/test/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
import java.util.InputMismatchException;
import java.util.Scanner;

public class Main {
import org.junit.jupiter.api.Test;

public class Main {
@SuppressWarnings({ "unused", "resource" })
public static void main(String[] args) {
MyThread t = null;
int option = 0;
boolean init = true;
Long time = null;
String guide = "|| Please insert option number";
String select1 = "| 1:start(120s)";
String select2 = "| 2:start with custom duration";
Expand All @@ -25,9 +29,16 @@ public static void main(String[] args) {
System.out.println("========================================================================");
Scanner input = new Scanner(System.in);
try {
option = input.nextInt();
if (init && args.length != 0 && "-t".equals(args[0])) {
option = 2;
time = Long.parseLong(args[1]);
} else {
option = input.nextInt();
}
} catch (InputMismatchException e) {
option = 999;
} catch (NumberFormatException e) {
option = 999;
}
if (option == 1) {
for (int i = 0; i < 50; i++) {
Expand All @@ -43,11 +54,14 @@ public static void main(String[] args) {
for (int i = 0; i < 50; i++) {
System.out.println("\n");
}
System.out.println("===============Input the detect duration(second)=================");
if (t != null) {
t.interrupt();
}
Long time = input.nextLong();
if (time == null) {
System.out.println("===============Input the detect duration(second)=================");
time = input.nextLong();
} else
System.out.println("=========================Script Started=========================");
t = new MyThread(time);
t.start();
} else if (option == 3) {
Expand All @@ -72,11 +86,12 @@ public static void main(String[] args) {
break;
} else if (option == 999) {
System.out.println(
"********************Your Input type error********************\n********************Please type number in.********************");
"********************Your Input or Argument type error********************\n********************Please type number in.********************");

} else {
System.out.println("********************Please use the numbers on the menu********************");
System.out.println("*************************Please use the numbers*************************");
}
init = false;
}

}
Expand All @@ -92,4 +107,10 @@ private static String rightPadding(String str, int length, char padChar) {
return String.format(pattern, str).replace(' ', padChar);
}

@Test
public void argTest() {
String a = "123qwezxcx";
System.out.println(Integer.parseInt(a));
}

}

0 comments on commit 1b9700c

Please sign in to comment.