I'm a beginner to Java, and I'm trying to write a simple Java program that calculates an amount in a savings account based on an initial amount deposited, number of years, and an interest rate. This is my code, which compiles, but does not actually print the amount of money in the account (basically, it completely ignores my second method).
import java.util.*;
class BankAccount {
public static Scanner input = new Scanner(System.in);
public static double dollars;
public static double years;
public static double annualRate;
public static double amountInAcc;
public static void main(String[] args) {
System.out.println("Enter the number of dollars.");
dollars = input.nextDouble();
System.out.println("Enter the number of years.");
years = input.nextDouble();
System.out.println("Enter the annual interest rate.");
annualRate= input.nextDouble();
}
public static void getDouble() {
amountInAcc = (dollars * Math.pow((1 + annualRate), years));
System.out.println("The amount of money in the account is " + amountInAcc);
}
}
I think it is because I don't call the method anywhere, but I'm a bit confused as to how/where I would do that.
BankAccount.getDouble();and print its result right before end ofmainmethod.