선생님이 정보를 저장하기 위해 ArrayList를 사용하는 방법을 보여 주었지만 문제가 있습니다. 내가 이해하지 못하는 것은 내가 배열 목록에 저장 한 "계정"을 참조하는 방법이고 그 다음에 그 방법을 적용하는 것이다. 예를 들어, 나는 ArrayList에 저장된 계정에 "deposit"메소드를 사용하려고합니다.은행 계좌 ArrayList
import java.util.Scanner;
import java.util.ArrayList;
public class Engine
{
public static void Engine()
{
ArrayList<BankAccount> accounts = new ArrayList<BankAccount>();
Scanner Reader = new Scanner(System.in);
BankAccount n = new BankAccount();
String response = Reader.nextLine();
boolean keepGoing = true;
while(keepGoing)
{
System.out.println("Welcome to The Bank of Money, what would you like to do?\n enter code hereenter n to create a new account, enter e to use an existing account, or enter q to quit to main menu");
response = Reader.nextLine();
if(response.equals("q")) keepGoing = false;
if(response.equals("n")) accounts.add(new BankAccount());
if(response.equals("e"))System.out.println("what is your account number?");
String accountNum = Reader.nextLine();
}
System.out.println("press 1 to deposit money");
System.out.println("press 2 to withdraw money");
System.out.println("press 3 to check your account balance");
System.out.println("press 4 to check your account's interest");
System.out.println("press 5 to quit");
String response2 = Reader.nextLine();
if (Reader.nextLine().equals("1"))
{
for(int i = 0; i<accounts.size();i++)
{
if (accounts.get(i).equals(accountNum))
{
accounts.get(i).deposit(amount);
}
}
}
}
}
내 업데이트 된 코드
제가 충분한 정보를 주셨으면 어떤 도움도 받으실 수 있습니다 – matt
은행 계좌 배열 목록을 입력하십시오. 선생님이 가르쳐 준 것이 필요하지 않습니까? – codebot
사용자 입력을 어떻게 확인합니까? 나는 스위치 문을 더 나은 옵션과 될 것입니다 또한 것 같아요. 안 그래? – Krishna