gpt4 book ai didi

java - Java-不匹配和方法未定义错误

转载 作者:行者123 更新时间:2023-12-03 08:39:59 25 4
gpt4 key购买 nike

//以下部分是引发错误的原因,我正在修改一个在线发现的简单银行应用程序。我刚接触Java大约三天了,因此我认为这是一项很好的小 Activity ,让我习惯了代码和方法等的语法。我一直在研究这个问题现在大约一天,无法弄清楚到底是什么问题。唯一会想到的是showMenu()方法可能超出了主要部分的范围,无法对其进行引用。
附言如果我错过了可能属于我们的任何事情,我深表歉意,因为我从未在这里发布过!
编辑-新的错误是:

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类中不可用的showMenu()。

关于java - Java-不匹配和方法未定义错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62498799/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com