Image

Imagereuptake wrote in Imagejava_dev 😯confused

Okay, I think I'm getting closer to understanding and completing my last assignment

The was a typo in the assignment though about the Name(): thing, it should be
Account(): configures a new account name with name "name", owner "owner", and balance "0"
Account(String s, String t, double n): configures a new account with name s, owner t, and balance n.



public class Account {
private String name;
private String owner;
private double balance;

public Account(){

String name = name;
String owner = owner ;
double balance = 0 ;


}
public Account(String s, String t, double n){
String owner = t;
String name = s;
n = 0;

}

public void deposit(double n){
balance = getBalance() + n;
}
public void setName(String s){
name = s ;
}
public void withdraw(double n){
balance = getBalance() - n ;
}
public void close(){
balance = getBalance() - getBalance();
}

public String getOwner() {
return owner;
}
public String getAccountName() {
return name ;
}
public double getBalance(){
return balance;
}
public void setOwner(String s){
owner = s;
}
public String getName(){
return name;
}
public String toString () {
String s = getName() ;
String t = getOwner();
double n = getBalance();
return s + "; " + t + "; " + n ;
}

}



When I try to compile, I get an error up in my default constructor Account() that my variables (name, owner, and balance) "might not have" initialized. I'm not understanding why.

And my toString is bad too, but I don't think I can mess with that until I get the rest of it working.

Thanks for all your help!

Edit: The assignment wants the initial balance to be 0. We're adding or subtracting "n" from our balance, so I know it's wrong to have "n" be equal to 0, because that's adding and subtracting nothing. I'm thinking I'm going to have to use "new" under my default constructor, right?