Question:
Java code error help?
Ledis15
2012-04-04 18:40:42 UTC
I keep getting this error. can someone help me fix it?

Exercise08_07.java:33: error: invalid method declaration; return type required
public account() {
^
1 error




public class Exercise08_07 {

public static void main (String[] args) {
account myAccount = new account();
myAccount.setId(1122);
myAccount.setBalance(20000, 2500, 3000);
myAccount.setAnnualInterestRate(.045);
System.out.println(myAccount.toString());
}
}


class Account {
// Implement it

private int id;

private double balance;
private double annualInterestRate;

private double withdraw;
private double deposit;
private double monthlyInterestRate;

public account() {
id = 0;
balance = 0;
annualInterestRate = 0;

}

public void setId(int i) {
id = i;
}
public int getId() {
return id;
}
public void setBalance(double bal, double wd, double dep) {
balance = bal;
withdraw = wd;
deposit = dep;
}
public double getBalance() {
return balance - withdraw + deposit;
}

public void setAnnualInterestRate(double air) {
annualInterestRate = air;
}

public double getAnnualInterestRate() {
return annualInterestRate;
}
public String toString() {
String printAccount = "";
printAccount += "For account: " + id + "\nBalance: " +
balance + "\nMonthly Interest Rate: " +
monthlyInterestRate;

return printAccount;

}


}
Four answers:
modulo_function
2012-04-04 18:50:45 UTC
That constructor misspells the name of the class.



Your class is

Account

not

account



Yes, your error is just that simple!
green meklar
2012-04-05 02:34:42 UTC
Java is case-sensitive. Accordingly, for a class with a given name, a constructor for that class must have the same name including the capitalization of the letters. Right now, you have a class called Account, but the constructor is called account(). This won't work. The constructor needs to be called Account() in order to match the class name.
Silent
2012-04-04 19:32:32 UTC
The name of your constructor has to be exactly the same as the name of your class. Exactly. "Account" and "account" are not exactly the same.



All names and keywords in Java are case-sensitive.
2012-04-04 18:58:17 UTC
Oh aha same thing happened to me u just have to delete your windows file 32.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...