EXAMPLE 1.1 An automated teller machine (ATM) enables a user to perform certain
ID: 3746281 • Letter: E
Question
EXAMPLE 1.1 An automated teller machine (ATM) enables a user to perform certain banking operations from a remote location. It must support the following operations. 1. Verify a user's Personal Identification Number (PIN 2. Allow the user to choose a particular account. 3. Withdraw a specified amount of money. 4. Display the result of an operation 5. Display an account balance. A class that implements an ATM must provide a method for each operation. We can write this requirement as the interface ATM and save it in file ATM.java, shown in Listing 1.1. The keyword interface on the header line indicates that an interface is being declared. If you are unfamiliar with the documentation style shown in this listing, read about Java documenta- tion at the end of Section A.7 in Appendix A LISTING . Interface ATM.java The interface for an ATM. public interface ATM t **Verifies a user's PIN @param pin The user's PIN @return Whether or not the User's PIN is verified boolean verifyPIN(String pin); A11ows the user to select an account. areturn a String representing the account selectedExplanation / Answer
I feel that this question is incomplete. But for the given part of the question, I assume you want to know how to implement a concrete implementation of ATM Interface and more specifically how would you implement verifyPIN() method.
Let me know in the comment if you realize that the question is incomplete. I'll edit my answer.
An interface can be implemented by using a keyword implements beside the class declaration.
In this case, we can define a concrete implementation of ATM something like...
class ATMImpl implements ATM {
@Override
void verifyPIN(String pinToBeVerified) {
// implementation.
}
}
Since there isn't much information on what to do within verifyPIN, I'll provide a typical example of how we do this.
We can do some basic sanity check like the size of the pin and the type of characters in it. Further, we can have some low level services that the ATMImpl can use to verify the acutal PIN.
An example of it can be -
boolean verifyPIN(String pin) {
// check if the length of the pin is 4
if(pin.length() != 4) return false;
for(int i=0; i<pin.length(); i++) {
// check if every character is a digit in it.
if(! Character.isDigit(pin.charAt(i))) return false;
}
}
Please note that this is just an example of the function implementation since no business rules were mentioned in the question. Please let me know in the comment if it has any specific business rule.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.