Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- import java.util.Scanner;
- public class Timer {
- public static String[] getCharLines(char char_) {
- switch (char_) {
- case '0':
- return new String[] { " ___ ", " / _ \\ ", " | | | |", " | | | |", " | |_| |", " \\___/ ", " ", " " };
- case '1':
- return new String[] { " __ ", " /_ |", " | |", " | |", " | |", " |_|", "", "" };
- case '2':
- return new String[] { " ___ ", " |__ \\ ", " ) |", " / / ", " / /_ ", " |____|", " ", " " };
- case '3':
- return new String[] { " ____ ", " |___ \\ ", " __) |", " |__ < ", " ___) |", " |____/ ", " ", " " };
- case '4':
- return new String[] { " _ _ ", " | || | ", " | || |_ ", " |__ _|", " | | ", " |_| ", " ", " " };
- case '5':
- return new String[] { " _____ ", " | ____|", " | |__ ", " |___ \\ ", " ___) |", " |____/ ", " ", " " };
- case '6':
- return new String[] { " __ ", " / / ", " / /_ ", " | '_ \\ ", " | (_) |", " \\___/ ", " ", " " };
- case '7':
- return new String[] { " ______ ", " |____ |", " / / ", " / / ", " / / ", " /_/ ", " ", " " };
- case '8':
- return new String[] { " ___ ", " / _ \\ ", " | (_) |", " > _ < ", " | (_) |", " \\___/ ", " ", " " };
- case '9':
- return new String[] { " ___ ", " / _ \\ ", " | (_) |", " \\__, |", " / / ", " /_/ ", " ", " " };
- case ':':
- return new String[] { " ", " _ ", " (_)", " ", " _ ", " (_)", " ", " ", " " };
- default:
- return new String[] { " ", " ", " ", " ", " ", " ", " ", " ", };
- }
- }
- public static String addZero(Integer number) {
- String number_ = String.valueOf(number);
- if (number <= 9) {
- number_ = "0" + String.valueOf(number);
- }
- return number_;
- }
- public static void clearTerminal() {
- try { // clear terminal
- if (System.getProperty("os.name").contains("Windows"))
- new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
- else
- Runtime.getRuntime().exec("clear");
- } catch (IOException | InterruptedException ex) {
- }
- }
- public static void main(String[] args) {
- System.out.println("Minutes:");
- Scanner scObj = new Scanner(System.in);
- Integer minutes = scObj.nextInt();
- System.out.println("seconds:");
- Integer seconds = scObj.nextInt();
- System.out.println(minutes + ":" + seconds);
- Boolean isFinished = false;
- while (isFinished == false) {
- seconds--;
- if (seconds < 0) {
- seconds = 59;
- minutes--;
- if (minutes < 0) {
- isFinished = true;
- break;
- }
- }
- clearTerminal();
- String minutes_ = addZero(minutes);
- String seconds_ = addZero(seconds);
- String[][] lines = { getCharLines(minutes_.charAt(0)), getCharLines(minutes_.charAt(1)), getCharLines(':'), getCharLines(seconds_.charAt(0)), getCharLines(seconds_.charAt(1)) };
- for (Integer i = 0; i < 7; i++) {
- System.out.println(lines[0][i] + " " + lines[1][i] + " " + lines[2][i] + " " + lines[3][i] + " " + lines[4][i]);
- }
- try {
- Thread.sleep(1000);
- } catch (Exception e) {
- //
- }
- }
- System.out.println("Timer finished!");
- System.out.println("Closing now.");
- try {
- Thread.sleep(5000);
- } catch (Exception e) {
- //
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement