ATM.zip in JAVA Contains the ATM classes and a simple implementation for a Card
ID: 3696316 • Letter: A
Question
ATM.zip in JAVA
Contains the ATM classes and a simple implementation for a Card class. Every card has a swipe method that takes in an ATM object that the card can use to validate is a real ATM. The ATM has a method applyDecryption() that the card must call to determine if the ATM has the proper credentials. The card must pass an encrypted code to applyDecryption() which will return a decrypted code. The card can then use this code to make sure the ATM has the appropriate private keys. If it does then the swipe method returns a Data object for ATM with info. (Look into Card.java below for how this is done).
This will show you an ATM UI. The Card.java contains the hardcoded pin.
ATM2 is the same except it does NOT pass an ATM object to the Card class so you have find the ATM class.
Problem
1. Modify the ATM class to allow the user to withdraw as much cash as there is in the machine. you do not have access to the source so you will have to resort to reflection. You can try this with the ATM.zip classes first since it already passes an ATM object to you.
2. Repeat Q1 but for ATM2 this time where an object is not passed to the Card. How do you get the ATM object? (This has to be the running object so simply doing an ATM a = new ATM() won't work. Do you understand why?).
3. There is a secret message in the ATM2 class. Find and decode it.
Hints
1. Use reflection to get the Methods/Fields of the ATM class.
2. Frame.getFrames gives you a list of all frames that are instantiated. ATM extends frame.
3. Here's a reference to the hidden message https://www.youtube.com/watch?v=zdA__2tKoIU
CODE:
public class Card {
private static String name = "Johnny Cash"; // Card holdersname
private static int cardNumber = 123456789; // Card holders number
private static int accountNumber = 978945; // Account number
private static int pinNumber = 1234; // Pin Number
private static int messageKey = 832923932; // Secret Message Key Encrypted
private static int messageResult = 13439; // Secret Message Key Decrypted
// Swipe method, this method takes in an ATM object and returns the cards data if the ATM
// is considered a valid one or returns null if the ATM is found to be invalid.
public static ATM.Data swipe(ATM anATM) {
int result = anATM.applyDecryption(messageKey);
if(result == messageResult) {
return new ATM.Data(cardNumber, accountNumber, name, pinNumber);
}
return null;
}
}
Explanation / Answer
Solution: Please follow these coding as shown in below..
import javax.swing.*;
public class ATM {
BankAccount []account = new BankAccount[10];
BankAccount ba = account[i];
String input;
public static void main ( String[] args){
new ATM();
}
public ATM(){
super();
start();
}
public String start(){
openNewAccount();
displayWelcomeScreen();
return null;
}
public int menuOptions(){
String []options = { "Withdraw", "Deposit" , "Check balance", "exit"};
int option = JOptionPane.showOptionDialog(null, "Hello! What would like to do?", "Menu Options", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, null);
if (option == 0)
ba.withdrawCash();
else if (option == 1)
ba.depositCash();
else if (option == 3)
ba.getBalance();
else {
JOptionPane.showMessageDialog(null, "Thank you for using the ATM.");
}
return option;
}
public void displayWelcomeScreen(){
String msg = " Welcome! Please insert your ATM card...";
input = JOptionPane.showInputDialog( null, msg, "ITB's ATM", JOptionPane.INFORMATION_MESSAGE);
if ( input.equals(BankAccount.accountNumber)) {
String inputPin = JOptionPane.showInputDialog(null, "Enter Pin Number:", "ITB's ATM", JOptionPane.INFORMATION_MESSAGE );
if (inputPin.equals(BankAccount.pinNumber)){
menuOptions();
}
}else{
JOptionPane.showInternalMessageDialog(null, "Error! Please insert card again");
displayWelcomeScreen();
}
}
public void openNewAccount(){
int i= 0;
if (account[i]== null && i < 10){
String name = JOptionPane.showInputDialog(null,"Please enter account name:", "Create New Account", JOptionPane.INFORMATION_MESSAGE);
String acctNum =JOptionPane.showInputDialog(null, "Please enter account number", "Create New Account", JOptionPane.INFORMATION_MESSAGE);
String acctNum2 =JOptionPane.showInputDialog(null, "Please verify account number", "Create New Account", JOptionPane.INFORMATION_MESSAGE);
if (acctNum == acctNum2){
account[i].setAcctNum(acctNum2);
}
String pin = JOptionPane.showInputDialog(null, "Please enter pin number", "Create New Account", JOptionPane.INFORMATION_MESSAGE);
account[i].setPin(pin);
}else{
JOptionPane.showMessageDialog(null, "Sorry but we can't accomodate new accounts as of this moment.");
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.