I instantiate an object with two parameters. While trying to pass another value (variable "interest").
I get error:
error: cannot find symbol
investor1.initialize(interest);
^
symbol: method initialize(double) location: variable investor1 of type Investor 1 error
Tool completed with exit code 1
Do I need to create another object? or what would be the right way to pass this value?
public static void main(String[] args){
Scanner stdIn = new Scanner(System.in);
Investor investor1 = new Investor (1001, 2000); //
System.out.print("Please enter the Annual Interest Rate you hope to earn; ");
double interest = stdIn.nextDouble();
investor1.initialize(interest); //here is where I get the error.
System.out.println("Monthly balances for one year with " + interest + " annual interest:");
System.out.printf("\n%s\t%s\t%s", "Month", "Account #", "Balance");
System.out.printf("\n%s\t%s\t%s\n", "-----", "---------", "-------");
for (int i = 0; i < 12; i++){
System.out.printf("\n%5d\t%9d\t%7.2f", i, investor1.getAccount(),investor1.getBalance());
}
Second part of code:
public class Investor{
private double interest;
private final int Account_Number;
private double balance;
//***********************************************************
public Investor(int account, double bal){
this.Account_Number = account;
this.balance = bal;
}
//********************************************************************
public void initialize(double temp){
this.interest = temp;
}
public double getInt(){
return interest;
}
public int getAccount(){
return this.Account_Number;
}
public double getBalance(){
return this.balance;
}
}//end of investor
Thanks for helping