Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

When attempting to compile my main Java program (to be used with a class) I rece

ID: 3920196 • Letter: W

Question

When attempting to compile my main Java program (to be used with a class) I receive:

Test.java:17: error: cannot find symbol

SavClass c = new SavClass(startBalance,intRate);

^ symbol: variable startBalance

location: class PTest

1 error

The compiler (jGRASP) seems to be saying that I need to declare a variable. However, other programs I have downloaded don't seem to need a variable declared when creating an object with the class. How can I fix this error. I have tried compiling this on a Windows 7 and 10 PCs but have the same error.

//Main program

import java.util.Scanner;

public class PTest{

public static void main(String[] args)

{

double bal = 0.00;

double intRate = 0.00;

int months = 0;

double depAmount;

double withAmount;

double totalDeposits = 0.00;

double totalWithdrawn = 0.00;

Scanner keyboard = new Scanner(System.in);

SavClass c = new SavClass(startBalance,intRate);

}

}

//Class

public class SavClass

{

private double balance;

private double withdraw;

private double deposit;

private double interestRate;

private double interest;

private double totalDeposits;

private double totalWithdrawn;

private double startBalance;

public SavClass (double startBalance,double intRate)

{

balance = startBalance;

interestRate = intRate;

interest = 0.00;

}

public double getBalance()

{

return balance;

}

}

Explanation / Answer

Hi

I have highlighted the changes. now it is compile error free. Here startbalance variable name bal. we hvae to use that variable name.

import java.util.Scanner;

public class PTest{

public static void main(String[] args)

{

double bal = 0.00;

double intRate = 0.00;

int months = 0;

double depAmount;

double withAmount;

double totalDeposits = 0.00;

double totalWithdrawn = 0.00;

Scanner keyboard = new Scanner(System.in);

SavClass c = new SavClass(bal,intRate);

}

}

//Class

public class SavClass

{

private double balance;

private double withdraw;

private double deposit;

private double interestRate;

private double interest;

private double totalDeposits;

private double totalWithdrawn;

private double startBalance;

public SavClass (double startBalance,double intRate)

{

balance = startBalance;

interestRate = intRate;

interest = 0.00;

}

public double getBalance()

{

return balance;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote