Accessor and Mutator Methods

Bank Class

public class Bank{
  private CheckingAccount accountOne;
  private CheckingAccount accountTwo;

  public Bank(){
    accountOne = new CheckingAccount("Zeus", 100, "1");
    accountTwo = new CheckingAccount("Hades", 200, "2");
  }

  public static void main(String[] args){
    Bank bankOfGods = new Bank();
    System.out.println(bankOfGods.accountOne.getBalance());
  }

}

Checking Account Class

public class CheckingAccount{
  private String name;
  private int balance;
  private String id;

  public CheckingAccount(String inputName, int inputBalance, String inputId){
    name = inputName;
    balance = inputBalance;
    id = inputId;
  }

  //Write new methods here:
  **public int getBalance() {**
**    return balance;**

**  } // getBalance method**
}

Exception Error
Error: Main method not found in class CheckingAccount, please define the main method as:
public static void main(String args)
or a JavaFX application class must extend javafx.application.Application

Hi, I am having a problem creating the accessor method. Based on the examples in the lesson I though I had this down. Please help explain what I am doing wrong. Not looking for the answer, looking for help to learn.

Thank you!

Hi, there!

Are you still having problems? While there is no option for Java for codebyte, you can format your code using…

image

Oddly enough, I do not have that option.

You do not see the option above your entry box?

Odd. However! You can use ctrl + e to use preformatted text as well.

I had to go digging for it in the settings icon.

After all that… coming back after a bit to clear my head I figured out the problem. I did not realize you must click “run” when you are focused on the Bank.java tab to invoke the program. I thought I could just click on “Run” from either of the two tabs.

This is sorted now. Thank you!

1 Like

Well, at least you learned one thing from all of this!

And you may find yourself becoming increasingly frustrated with coding problems in the future. It is always a good idea to take a step back to get a breather before returning to the problem, as a fresh mind can allow you to look at things from a different perspective.

Keep on keeping on!

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.