-1

my Main class look like the following:

public class Main {

    public static void main(String[] args)
    {
        Account account=new Account();
        account.deposit(amount:10);
        System.out.println(account.getBalance());
    }
}

and Account class as below:

public class Account {
    private float balance;
    public void deposit(float amount){
        if(amount>0)
        balance+=amount;
    }
}

I get an java ) expected error, which refers to the line "account.deposit(amount:10);" in Main class and hints, that amounts can not be resolved, but i dont understand why, could you give me some hint.

shafigh
  • 61
  • 1
  • 2
  • 10

1 Answers1

1

Change

account.deposit(amount:10);

to

account.deposit(10);

or

account.deposit(10.0f);

You can't label parameters that way at the caller's site. Also, don't forget to implement getBalance(). And use brackets ({}) even when they're optional.

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249