Answered step by step
Verified Expert Solution
Question
1 Approved Answer
100 import javax.swing.JFrame; 11 import javax.swing. JOptionPane; 13 public class Applications extends JFrame { public static void main(String[] args) { Account acc = null;
100 import javax.swing.JFrame; 11 import javax.swing. JOptionPane; 13 public class Applications extends JFrame { public static void main(String[] args) { Account acc = null; ATM atm = null; SFSCHNACKDNP8555550558 22 | 33 34 35 36 37 38 39 $40 41 42 43 44 45 46 47 48 49 $50 51 52 53 54 55 56 57 58 59 60 61 62 boolean client = true; boolean transaction Required = true; Applications app = new Applications(); // ask the user if they want to open an account, output will depends on their answer // if yes will continue the program, if either cancel or no will close the program while(client) { int result = JOptionPane.showConfirmDialog( app, "Would you like to open an account? " + "The minimum deposit is 100 dollars. " + "If you have an account please click Cancel", "Client Window", JOptionPane. YES_NO_CANCEL_OPTION, JOptionPane. QUESTION_MESSAGE ); if(result JOptionPane.YES_OPTION) { acc = new Account (); atm = new ATM (acc); } else if(result == JOptionPane.NO_OPTION) { client = false; } else if(result == JOptionPane.CANCEL_OPTION) { if(acc != null) { } == atm = new ATM(acc); transaction Required = true; while(transactionRequired) { int yesNo = JOptionPane.showConfirmDialog( app, "Please click Yes for a transaction Click No to exit current process.", "Client Window", JOptionPane. YES_NO_OPTION, ); JOptionPane.QUESTION_MESSAGE if(yesNo== JOptionPane.YES_OPTION) { atm. transaction(); } } else { } else if(yesNo== JOptionPane.NO_OPTION) { transactionRequired = false; } JOptionPane.showMessageDialog(app, "Sorry, you do not have an account.", "Client Window", JOptionPane. ERROR_MESSAGE); client = false; *Account.java 100 import java.util.Scanner; 11 import javax.swing.JFrame; 12 import javax.swing. JOptionPane; 13 14 public class ATM extends JFrame { 15 16 17 18 190 20 21 22 23 24 25 26 270 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 (3 *Applications.java private Account acc; private Scanner keyboard; public ATM(Account account) { this.acc = account; this.keyboard = new Scanner(System.in); transaction(); } // ask to enter the PIN code that was given to the user before, if correct will continue the program // otherwise will stop and ask you again public void transaction() { System.out.println("Please enter your PIN code here: "); int pin = keyboard.nextInt (); ); ATM.java X // ask either want to withdraw or deposit, or maybe you can use W for withdraw, D for deposit if(acc.getPin() == pin) { String input = (String) JOptionPane.showInput Dialog( rootPane, "Please enter W or w to withdraw Enter D or d for deposit", "Input", JOptionPane. QUESTION_MESSAGE, null, null, 1111 if(input.equalsIgnoreCase("w")) { String withdrawStr = (String) JOptionPane.showInputDialog( rootPane, "Please enter the amount you want to withdraw", "Input", JOptionPane.QUESTION_MESSAGE, null, null, 11 11 ); double withdrawValue = Double.valueOf(withdrawStr); this.acc.withdraw(withdrawValue); this.acc.showBalance(); // tell the user that we accept only the following bills, if enter the available bills will continue // otherwise will end the program } else if (input.equalsIgnoreCase("d")) { JOptionPane.showMessageDialog(rootPane, "We accept the following dollar bills: " + "1, 5, 10, 20, 50, 100 " + "Please insert the bill on the console " + "Enter any other number to stop depositing", "Message", JOptionPane. INFORMATION_MESSAGE); *Account.java J 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84} *Applications.java ATM.java X 17 USK Cacher ware wame co CO WECHIMI un vi exposic, or mayor you can use it for WeCharaw, for acposic if(acc.getPin() == pin) { String input = (String) JOptionPane.showInput Dialog( rootPane, "Please enter W or w to withdraw Enter D or d for deposit", "Input", } ); JOptionPane.QUESTION_MESSAGE, null, null, 1111 if(input.equals IgnoreCase("w")) { String withdrawStr = (String) JOptionPane.showInputDialog( rootPane, "Please enter the amount you want to withdraw", "Input", JOptionPane.QUESTION_MESSAGE, null, null, ); double withdrawValue = Double.valueOf(withdrawStr); this.acc.withdraw(withdrawValue); } } else { } this.acc.showBalance(); // tell the user that we accept only the following bills, if enter the available bills will continue // otherwise will end the program } else if (input.equalsIgnoreCase("d")) { JOptionPane.showMessageDialog(rootPane, "1, 5, 10, 20, 50, 100 " + "Please insert the bill on the console " + "Enter any other number to stop depositing", "Message", JOptionPane. INFORMATION_MESSAGE); System.out.println("Enter the bills here:"); double depositValue = 0.0; double lastInput = 0.0; do { "We accept the following dollar bills: " lastInput = keyboard.nextDouble(); if(lastInput == 1 || lastInput % 5 == 0) { depositValue += lastInput; } } while(lastInput == 1 || lastInput % 5 == 0); this.acc.deposit (depositValue); this.acc.showBalance(); System.out.println("Wrong PIN, transaction aborted."); *Account.java X *Applications.java 110 import java.util.Random; 14 15 public class Account extends JFrame { 16 17 18 19 20 21 220 23 24 25 26 27 28 29 30 31 32 33 34 35 36 private double balance; private int pin; *I*328**N*********RARORA BUY //ask the user what is the amount for deposit //give the user the PIN for his account and tell them to take a note of it public Account() { } String balanceStr = (String) JOption Pane.showInputDialog( rootPane, ); } 37 380 public int getPin() { return pin; ATM.java "Please enter the amount for deposit Please take note a PIN code will be issued for you", "Client Window", JOptionPane. WARNING_MESSAGE, null, null, this.balance Double.valueOf (balanceStr); createPin(); JOptionPane.showMessageDialog(rootPane, "Take note of your PIN: " + pin, "Client Window", JOptionPane. WARNING_MESSAGE) ; } = } public void createPin() { if(pin == 0) { pin = new Random() .nextInt(99991000) + 1000; } else { public void setBalance (double balance) { this.balance = balance; } // show the balance of the account public void showBalance() { JOptionPane.showMessageDialog(this, "The current balance is " + String.format("$%.2f", balance), "Message", JOptionPane. INFORMATION_MESSAGE); } public void deposit (double value) { this.balance += value; } public void withdraw(double value) { if(value> balance) { System.out.println("Required amount exceeds balance. You receive your balance."); this.balance -= value;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started