uhheeYt

Java TimeCheck Class (Updates Regularly)

Jan 16th, 2022 (edited)
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.90 KB | None | 0 0
  1. public static List<String> logs = new ArrayList<String>();
  2. public static class ErrorHandler {
  3.         public static class timeErrors {
  4.             public static void error0fx4() {
  5.                 System.out.println("Invalid time format. Please try again.");
  6.                 logs.add("Error 0fx4: Time hour bigger than 24 or smaller than 0");
  7.             }
  8.             public static void error0fx5() {
  9.                 System.out.println("Invalid time format. Please try again.");
  10.                 logs.add("Error 0fx5: Time minute bigger than 59 or smaller than 0");
  11.             }
  12.         }
  13.  
  14.     }
  15. public static final class timeCheck {
  16.         public static void printRules() {
  17.             System.out.println("1. Do not put more than 59 minutes\n2. Do not put less than 0 minutes.\n3. DO NOT, IN ANY CASE, MAKE THE HOUR SINGLE DIGIT. PUT A ZERO BEHIND IT.\n4. Do not put more than 24 hours.\n5. Do not put less than 0 hours.");
  18.         }
  19.         public static void checkAfternoon(double time) {
  20.             String timeStr = String.valueOf(time);
  21.             if (time > 24 || time < 0) { // error check
  22.                 ErrorHandler.timeErrors.error0fx4();
  23.             } else if (time < 10) { // exception of errors: needed for next error check
  24.                 timeStr = "0" + timeStr;
  25.                 time = Double.parseDouble(timeStr);
  26.             } else if (Integer.parseInt(String.valueOf(timeStr.charAt(3))) >= 6 || Integer.parseInt(String.valueOf(timeStr.charAt(3))) < 0) {
  27.                 ErrorHandler.timeErrors.error0fx5();
  28.             } else { // code running
  29.                     boolean passed;
  30.                     if (time < 12) {
  31.                         passed = false;
  32.                     } else {
  33.                         passed = true;
  34.                     }
  35. //                    System.out.println(time);
  36.                     System.out.println(passed);
  37.                 }
  38.             }
  39.         }
Add Comment
Please, Sign In to add comment