Применение мини-банкомата
Поэтому я создаю приложение mini ATM, и у меня есть несколько проблем с ним.
1. он зацикливается после того, как я прошу его снять
2. не несет newBalance на протяжении всей программы
3.Мне нужна дополнительная функция, отличная от вывода средств, депозита и отображения баланса
Что я уже пробовал:
import java.util.*; public class ATM { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner (System.in); String acctNum,password,orignalBalance="error"; int mainMenu=0; int counter=3; double x=0; do { System.out.println("Enter the account number:"); acctNum=input.next(); System.out.println("Enter the pin:"); password=input.next(); orignalBalance=validation(acctNum,password); counter--; if(counter==0) { System.out.println("Maximum amount of attempts"); break; } else if(!(orignalBalance.equals("error"))) { break; } }while(orignalBalance.equals("error")); { double balance=Double.parseDouble(orignalBalance); mainMenu=mainMenuOption(); while(!(mainMenu==4)) if (mainMenu==1) { x=withdrawl(balance); System.out.println("Balance= $"+x); } else if (mainMenu==2) { x=deposit(balance); System.out.println("Balance= $"+x); } } } public static double deposit(double balance) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); double deposit=0; double newBalance=0; System.out.println("How much money would you like to input?"); deposit=input.nextDouble(); newBalance=balance+deposit; return newBalance; } public static int mainMenuOption() { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); int userInput=0; System.out.println("\nWhat would you like to do today?"); System.out.println("1. Withdrawl"); System.out.println("2. Deposit"); System.out.println("3. Bank Balance"); System.out.println("4. Recipt Bank Balance"); System.out.println("5. Exit"); userInput=input.nextInt(); return userInput; } public static double withdrawl(double balance) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); double withdrawAmt=0; double newBalance=0; System.out.println("How much money would you like to withdraw today"); withdrawAmt=input.nextDouble(); if(withdrawAmt<balance) { newBalance=balance-withdrawAmt; } return newBalance; } public static String validation(String acctNum,String password) { // TODO Auto-generated method stub String a="123456 mypassword 54.6"; String b="723456 anotherpassword 900.0"; String c="823456 bestpassword 438.32"; String result = "error"; if (acctNum.equals(a.substring(0, a.indexOf(" "))) && password.equals(a.substring(a.indexOf(" ")+1,a.lastIndexOf(" ")))) return result = a.substring(a.lastIndexOf(" ") + 1); if (acctNum.equals(a.substring(0, b.indexOf(" "))) && password.equals(a.substring(a.indexOf(" ")+1,a.lastIndexOf(" ")))) return result = a.substring(a.lastIndexOf(" ") + 1); if (acctNum.equals(a.substring(0, c.indexOf(" "))) && password.equals(a.substring(a.indexOf(" ")+1,a.lastIndexOf(" ")))) return result = a.substring(a.lastIndexOf(" ") + 1); else { System.out.println("Wrong username or password"); } return result; } }