• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

need help with java homework

alfa147x

Lifer
im trying to compile this script:

import java.util.Random;



public class BankAccount
{



private double balance;

//Make tank

public tank();
{
balance = 0;


//consturct





}

//deposite

public void deposit(double amount)

{
double newBalance = balance + amount;
balance = newBalance;
}







//Take out

public void withdraw(double amount)

{
double newBalance = balance - amount;
balance = newBalance;
}



//Get balance


public double getBalance()
{
return balance;
}

}



I get this error:

BankAccount.java:14: invalid method declaration; return type required
public tank();
^
1 error
Press any key to continue . . .


 
Your tank() method requires a return type. It looks like you don't intend on returning anything when the method finishes, so it should look like this (you're forgetting the void keyword):

public void tank() {
balance = 0;
}
 
Originally posted by: alfa147x
public tank();
{
balance = 0;
}


I get this error:

BankAccount.java:14: invalid method declaration; return type required
public tank();
^
Well, read the message... it's complaining because you're defining a method tank() but not saying what that method returns. i.e. Is it supposed to return an integer? A boolean? Nothing at all?

If the idea of "a function returning a value" is not something you're familiar with, then say so and I'll be more explicit.

 
Also, in your deposit() and withdraw() methods, you don't need to declare a new double variable and then make your balance variable equal to that. I mean it works but it's unnecessary. 🙂
 
Back
Top