util.java (1524B)
1 package space.nocebo; 2 3 import java.util.regex.PatternSyntaxException; 4 import java.util.Random; 5 6 public class util { 7 private static int prev = getRandomInt(); 8 private static int t = 0; 9 10 public static boolean isNumeric(String s) { 11 try { 12 int d = Integer.parseInt(s); 13 } catch (NumberFormatException | NullPointerException ex) { 14 return false; 15 } 16 return true; 17 } 18 19 public static boolean isDouble(String s) { 20 try { 21 double d = Double.parseDouble(s); 22 } catch (NumberFormatException | NullPointerException ex) { 23 return false; 24 } 25 return true; 26 } 27 28 public static boolean isValidCred(String s) { 29 try { 30 String[] a = s.split(" ", 2); 31 if (a.length < 2) 32 return false; 33 } catch (PatternSyntaxException ex) { 34 return false; 35 } 36 return true; 37 } 38 39 public static int getRandomInt() { 40 int res = 0; 41 Random r = new Random(); 42 res = r.nextInt((5-1) + 1) + 1; 43 return res; 44 } 45 46 public static String getAlphaNumString() { 47 String AlphaNumericString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 48 + "0123456789" 49 + "abcdefghijklmnopqrstuvxyz"; 50 StringBuilder sb = new StringBuilder(10); 51 for (int i = 0; i < 10; i++) { 52 int index = (int)(AlphaNumericString.length()* Math.random()); 53 sb.append(AlphaNumericString.charAt(index)); 54 } 55 return sb.toString(); 56 } 57 58 public static int getRandomScore() { 59 int s; 60 61 if (t == 3) { 62 t = 0; 63 s = getRandomInt(); 64 System.out.println("dbg: s: " + s); 65 prev = s; 66 } else { 67 if (prev >= 5) 68 prev = 1; 69 s = prev + 1; 70 } 71 72 t++; 73 return s; 74 } 75 }