簡體   English   中英

Java - 不匹配和方法未定義錯誤

[英]Java - Mismatch and method is undefined error

// 下面的部分是引發錯誤的原因,我正在修改我在網上找到的一個簡單的銀行應用程序。 我對 Java 非常陌生,我已經涉足了大約 3 天,並認為這是一個很好的小活動,可以讓我習慣代碼和方法的語法等。我一直在研究這個問題現在大約一天,無法弄清楚到底是什么問題。 唯一想到的是 showMenu() 方法可能超出了 scope 的主要部分,但我不確定。

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);

我認為您正在嘗試調用 BankAccount class 中不可用的 showMenu()。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM