-1

// 下面的部分是引发错误的原因,我正在修改我在网上找到的一个简单的银行应用程序。我对 Java 很陌生,大约 3 天我一直在涉足它,并认为这是一个很好的小活动,可以让我习惯代码和方法的语法等。我一直在研究这个问题现在大约一天,无法弄清楚到底是什么问题。唯一想到的是 showMenu() 方法可能超出了我引用它的主要部分的范围,但我不确定。

PS如果我错过了任何可能属于我们的东西,我很抱歉,因为我以前从未在这里发布过!

编辑 - 新错误是:

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    The constructor BankApplication.BankAccount(String, String) is undefined
    The method showMenu() is undefined for the type BankApplication.BankAccount

    at BankApplication.main(bank.java:9)




public static void main(String[] args)
{
 BankAccount obj1 = new BankAccount("Ye Ma", "X Æ A-12");
 obj1.showMenu();
}

//showMenu代码

void showMenu()
{
    Scanner sc = new Scanner(System.in);

    System.out.println("Welcome to the Bank");
    System.out.println("Your Customer ID is: " + cID);
    System.out.println("");

    System.out.println("1. To view you Bank Balance.");
    System.out.println("2. To make a deposit.");
    System.out.println("3. To make a withdrawel.");
    System.out.println("4. To view your previous transaction.");
    System.out.println("5. To exit.");
    
    do
    {
        System.out.println("----------------------------------------------------------------------");
        System.out.println("        Choose an option        ");
        System.out.println("----------------------------------------------------------------------");
        System.out.println("");
        option = sc.nextInt();

        if(option == 1)
        {
            System.out.println("----------------------------------------------------------------------");
            System.out.println("  Your bank balance is: " + balance);
            System.out.println("----------------------------------------------------------------------");

            break;
        }
        else if(option == 2)
        {
            System.out.println("----------------------------------------------------------------------");
            System.out.println("How much would you like to deposit?");
            System.out.println("----------------------------------------------------------------------");
            int amount = sc.nextInt();
            deposit(amount);
            break;
        } 
        else if(option == 3)
        {
            System.out.println("----------------------------------------");
            System.out.println("  How much would you like to withdraw?: ");
            System.out.println("----------------------------------------------------------------------");
            int amount = sc.nextInt();
            withdraw(amount);
            break;
        }
        else if(option == 4)
        {
            System.out.println("----------------------------------------------------------------------");
            System.out.println("Your previous transaction was: " + getPreviousTransaction(amount));
            System.out.println("----------------------------------------------------------------------");
            System.out.println("");
        }
        else if(option == 5)
        {
            System.out.println("**********************************");
            System.out.println("        END OF APPLICATION        ");
            System.out.println("**********************************");
        }

        else
        {
            System.out.println("Invalid option, please choose a valid option.");
        }
    }while(option != 5);
4

1 回答 1

0

我认为您正在尝试调用 BankAccount 类中不可用的 showMenu() 。

于 2020-06-21T13:38:24.103 回答