Trying to invoke a method called addAccount for a bank application but it keeps giving me .class is expected error

后端 未结 3 1954
北海茫月
北海茫月 2021-01-26 11:25

This has been giving me error when I try to invoke the addAccount method saying .class is expected on the line where I try to invoke it.
I am trying to do an as

相关标签:
3条回答
  • 2021-01-26 11:41

    you have declared it static so you need to add the class name before the call

    bank.addAccount(int accountNo,double accountBal);
    

    and instead of the types decleration you have to call it with parameters.

    bank.addAccount(accountNo,accountBal);
    
    0 讨论(0)
  • 2021-01-26 11:49

    Do not specify parameter type while calling a method.

    Here is an error:

    case 1 : addAccount(int accountNo,double accountBal);
    

    It must be:

    case 1 : addAccount(accountNo,accountBal); break;
    
    0 讨论(0)
  • 2021-01-26 12:01

    You are missing a closing curly bracket before the definition of the displayMenu method. The following version is syntactically correct:

    public class Bank {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int choice = 0;
            int accountNo = 0;
            double accountBal = 0;
            int[] accountNoArray = new int[20];
            int[] accountBalArray = new int[20];
            displayMenu();
            System.out.print("Please Enter Your Choice: ");
            choice = sc.nextInt();
            if (choice == 1) {
                System.out.print("Please Enter NRIC number: ");
                accountNo = sc.nextInt();
                System.out.print("Please Enter Account Balance: ");
                accountBal = sc.nextInt();
            }
        }
    
        public static void displayMenu() {
            System.out.println("Menu");
            System.out.println("1. Add an account");
            System.out.println("2.Search an account with the given account number");
            System.out.println("3.Display accounts below the given balance");
            System.out.println("4.Exit");
        }
    
        public static void addAccount(int accountNo, double accountBal) {
    
        }
    }
    
    0 讨论(0)
提交回复
热议问题