ATM.zip Contains the ATM classes and a simple implementation for a Card class. E
ID: 3576721 • Letter: A
Question
ATM.zip
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 for how this is done).
To see it in action, do the following in the ATM unzipped folder
This will show you an ATM UI. The Card.java contains the hardcoded pin.
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.
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.
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
Sometimes the terms function and method are used interchangeably. They are virtually the same. The correct terminology for Java is method. It is a set of commands that can be used over again. In this, they share similarities with sub routines in the early days of programming.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.