hello I'm new to java and I'm confused on how I should write JUnit test can someone help?
The task instructions:
When you use an automated teller machine (ATM) with your bank card, you need to use a personal identification number (PIN) to access your account. If a user fails more than three times when entering the PIN, the machine will block the card.
Assume that the user's PIN is “1234” and write a program that asks the user for the PIN no more than three times, and does the following:
import java.util.Scanner;
public class BankingSystemWithPin {
private static int pinAttempts = 0;
public static void main(String[] args) {
BankAccount bankAccount1 = new BankAccount("RO29455302311322", 200, "1234");
BankAccount bankAccount2 = new BankAccount("RO43593530521134", 600, "7530");
BankAccount[] bankAccounts = {bankAccount1, bankAccount2};
Scanner scanner = new Scanner(System.in);
BankAccount currentBankAccount = null;
while (currentBankAccount == null) {
pinAttempts++;
if (pinAttempts > 3) {
System.err.println();
System.err.println("You have exceeded the allowable number of login attempts!");
System.err.println("The transaction is over. ");
System.exit(0);
}
Menu.welcome();
String pin = scanner.nextLine();
currentBankAccount = BankingSystemWithPin.getBankAccountByPin(bankAccounts, pin);
}
// PIN correct and account number acquired!
ATM.useATM(currentBankAccount);
}
public static BankAccount getBankAccountByPin(BankAccount[] bankAccounts, String pin) {
for (BankAccount bankAccount : bankAccounts) {
if (bankAccount.pin.equals(pin)) {
System.out.println();
System.out.println("Account Number: " + bankAccount.IBAN);
return bankAccount;
}
}
System.err.println("Wrong Pin. Try Again.");
System.err.println();
return null;
}
}
Just s few pointers;
That done, it should be simple to at least test the ATM class.methods. Testing user input logic is somewhat more difficult and is often done manually.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.