diff --git a/Code/ATM.java b/Code/ATM.java index 60b5e5e..00f6836 100644 --- a/Code/ATM.java +++ b/Code/ATM.java @@ -5,6 +5,9 @@ public class ATM { private int minimumAmount; private int maximumAmount; private int limitTimeForOperation; + private int totalFund; + private int maximum_withdrawar_pday_pacc; + private int maximum_withdrawar_ptrans; /** * @@ -62,5 +65,30 @@ public class ATM { public void setLimitTimeForOperation(int limitTimeForOperation) { this.limitTimeForOperation = limitTimeForOperation; } + + public int getMaximum_withdrawar_pday_pacc() { + return maximum_withdrawar_pday_pacc; + } + + public void setMaximum_withdrawar_pday_pacc(int maximum_withdrawar_pday_pacc) { + this.maximum_withdrawar_pday_pacc = maximum_withdrawar_pday_pacc; + } + + public int getMaximum_withdrawar_ptrans() { + return maximum_withdrawar_ptrans; + } + + public void setMaximum_withdrawar_ptrans(int maximum_withdrawar_ptrans) { + this.maximum_withdrawar_ptrans = maximum_withdrawar_ptrans; + } + + + public int getTotalFund() { + return totalFund; + } + + public void setTotalFund(int totalFund) { + this.totalFund = totalFund; + } } diff --git a/Code/Display.java b/Code/Display.java index 3bd95e7..36db3b5 100644 --- a/Code/Display.java +++ b/Code/Display.java @@ -42,4 +42,15 @@ public class Display { throw new UnsupportedOperationException(); } -} \ No newline at end of file + public static String get_default_display() { + StringBuilder sb = new StringBuilder(); // Use StringBuilder for efficiency + sb.append("------------------------------------\n"); + sb.append("Welcome to the ATM\n"); + sb.append("1. Check Balance\n"); + sb.append("2. Withdraw Cash\n"); + sb.append("3. Deposit Cash\n"); + sb.append("------------------------------------\n"); + return sb.toString(); + } + +} diff --git a/Code/Loop.class b/Code/Loop.class new file mode 100644 index 0000000..703d505 Binary files /dev/null and b/Code/Loop.class differ diff --git a/Code/Loop.java b/Code/Loop.java new file mode 100644 index 0000000..eb868a8 --- /dev/null +++ b/Code/Loop.java @@ -0,0 +1,66 @@ +import java.util.HashMap; +import java.util.Map; + +public class Loop { + + public static Map parseCommandLineArgs(String[] args) { + Map parameters = new HashMap<>(); + try { + for (int i = 0; i < args.length; i++) { + if (args[i].startsWith("-")) { + String parameterName = args[i].substring(1); + if (i + 1 < args.length) { + try { + int parameterValue = Integer.parseInt(args[i + 1]); + parameters.put(parameterName, parameterValue); + i++; + } catch (NumberFormatException e) { + System.err.println("Error: Invalid value for parameter " + parameterName + ": " + args[i + 1]); + return null; + } + } else { + System.err.println("Error: Missing value for parameter " + parameterName); + return null; + } + } else { + System.err.println("Warning: Ignoring invalid argument: " + args[i]); + } + } + } catch (Exception e) { + System.err.println("An unexpected error occurred: " + e.getMessage()); + return null; + } + + return parameters; + } + + public static void main(String[] args) { + Map atmParams = parseCommandLineArgs(args); + + if (atmParams != null) { + int t = atmParams.getOrDefault("t", 0); + int k = atmParams.getOrDefault("k", 0); + int m = atmParams.getOrDefault("m", 0); + int n = atmParams.getOrDefault("n", 0); + + ATM atm = new ATM(); + CardReader cr = new CardReader(atm); + Display display = new Display(); + display.display(Display.get_default_display()); + atm.setMinimumAmount(n); + atm.setTotalFund(t); + atm.setMaximum_withdrawar_pday_pacc(k); + atm.setMaximum_withdrawar_ptrans(m); + + while (true) { + + if ATM.checkAvailabilityOfCashInATM() + // TODO wait for signal from + + } + + } else { + System.err.println("Failed to initialize ATM parameters from command line."); + } + } +}