mmayoub

Bank, BankUtils class

Aug 10th, 2017
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.93 KB | None | 0 0
  1. package BankPkg;
  2.  
  3. import java.time.LocalDate;
  4. import java.time.temporal.ChronoUnit;
  5. import java.util.Arrays;
  6.  
  7. public class BankUtils {
  8.     public static final int minClientAge = 16;
  9.     public static final int minNameLength = 2;
  10.     public static final int minId = 100000000;
  11.     public static final int maxId = 999999999;
  12.  
  13.     public static final double minLoanFee = 0.01;
  14.     public static final double maxLoanFee = 0.10;
  15.  
  16.     protected static double loanFee = 0.02;
  17.  
  18.     public static double getLoanfee() {
  19.         return BankUtils.loanFee;
  20.     }
  21.  
  22.     protected static boolean setLoanFee(double loanFee) {
  23.         if (BankUtils.isBetween(loanFee, minLoanFee, maxLoanFee)) {
  24.             BankUtils.loanFee = loanFee;
  25.             return true;
  26.         }
  27.  
  28.         return false;
  29.     }
  30.  
  31.     public static boolean isValidId(int id) {
  32.         return (id >= BankUtils.minId && id <= BankUtils.maxId);
  33.  
  34.     }
  35.  
  36.     public static boolean isValidName(String name) {
  37.  
  38.         String[] words = name.split(" ");
  39.         for (String item : words) {
  40.             // every word is letters only and has enough chars
  41.             if (!item.matches("[a-zA-Z]{" + BankUtils.minNameLength + ",}")) {
  42.                 return false;
  43.             }
  44.         }
  45.         return true;
  46.     }
  47.  
  48.     public static LocalDate dublicate(LocalDate date) {
  49.         return date.plusDays(0);
  50.     }
  51.  
  52.     public static long getAge(LocalDate birthDate) {
  53.         return ChronoUnit.YEARS.between(birthDate, LocalDate.now());
  54.     }
  55.  
  56.     public static long getAge(LocalDate birthDate, LocalDate atDate) {
  57.         return ChronoUnit.YEARS.between(birthDate, atDate);
  58.     }
  59.  
  60.     public static boolean isBetween(double num, double min, double max) {
  61.         return (num >= min && num <= max);
  62.     }
  63.  
  64.     public static Object[] addToArray(Object[] array, Object obj) {
  65.         Object[] result = Arrays.copyOf(array, array.length + 1);
  66.         result[result.length - 1] = obj;
  67.  
  68.         return result;
  69.     }
  70.  
  71.     public static int[] addToArray(int[] array, int num) {
  72.         int[] result = Arrays.copyOf(array, array.length + 1);
  73.         result[result.length - 1] = num;
  74.  
  75.         return result;
  76.     }
  77.  
  78. }
Add Comment
Please, Sign In to add comment