Incorrect object instantiation?

Viewed 37

I have this code that's supposed to get inputs from users such as interest rate, deposit amount, and print the balance. The issue is that I'm getting the "cannot find symbol" errors on my main method. Did I incorrectly call the savingsAccount class? Also, I can't change anything on the savingsAccount class. The code is 85% complete btw.

import java.util.*;

public class RunSavingsAccount{
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        savings.SavingsAccount();
        
        System.out.print("Enter interest rate: ");
        interestRate = input.nextDouble();
        System.out.print("Enter deposit amount: ");
        deposit = input.nextDouble();
        System.out.println("Your balance is " + balance);
        
        System.out.print("Press D for another deposit or W to withdraw");
        System.out.print("Enter deposit amount: ");
        deposit = input.nextDouble();
        
        System.out.println("You new balance is " + balance);
        
    }
}

class SavingsAccount{
    private double balance;
    public static double interestRate = 0;
    
    public SavingsAccount(){
        balance = 0;
    }
    
    public static void setInterestRate(double newRate){
        interestRate = newRate;
    }
    
    public static double getInterestRate(){
        return interestRate;
    }
    
    public double getBalance(){
        return balance;
    }
    
    public void deposit(double amount){
        balance += amount;
    }
    
    public double withdraw(double amount){
        if (balance >= amount){
            balance -= amount;
        } 
        else{
            amount = 0;
            return amount;
            
        }
    }
    
    public void addInterest(){
        double interest = balance * interestRate;
        balance += interest;
    }
    
    public static void showBalance(SavingsAccount account){
       System.out.print(account.getBalance());
    }
    
    
}
0 Answers
Related