Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package BankPkg;
- import java.time.LocalDate;
- import java.time.temporal.ChronoUnit;
- import java.util.Arrays;
- public class BankUtils {
- public static final int minClientAge = 16;
- public static final int minNameLength = 2;
- public static final int minId = 100000000;
- public static final int maxId = 999999999;
- public static final double minLoanFee = 0.01;
- public static final double maxLoanFee = 0.10;
- protected static double loanFee = 0.02;
- public static double getLoanfee() {
- return BankUtils.loanFee;
- }
- protected static boolean setLoanFee(double loanFee) {
- if (BankUtils.isBetween(loanFee, minLoanFee, maxLoanFee)) {
- BankUtils.loanFee = loanFee;
- return true;
- }
- return false;
- }
- public static boolean isValidId(int id) {
- return (id >= BankUtils.minId && id <= BankUtils.maxId);
- }
- public static boolean isValidName(String name) {
- String[] words = name.split(" ");
- for (String item : words) {
- // every word is letters only and has enough chars
- if (!item.matches("[a-zA-Z]{" + BankUtils.minNameLength + ",}")) {
- return false;
- }
- }
- return true;
- }
- public static LocalDate dublicate(LocalDate date) {
- return date.plusDays(0);
- }
- public static long getAge(LocalDate birthDate) {
- return ChronoUnit.YEARS.between(birthDate, LocalDate.now());
- }
- public static long getAge(LocalDate birthDate, LocalDate atDate) {
- return ChronoUnit.YEARS.between(birthDate, atDate);
- }
- public static boolean isBetween(double num, double min, double max) {
- return (num >= min && num <= max);
- }
- public static Object[] addToArray(Object[] array, Object obj) {
- Object[] result = Arrays.copyOf(array, array.length + 1);
- result[result.length - 1] = obj;
- return result;
- }
- public static int[] addToArray(int[] array, int num) {
- int[] result = Arrays.copyOf(array, array.length + 1);
- result[result.length - 1] = num;
- return result;
- }
- }
Add Comment
Please, Sign In to add comment