Question: INTRO JAVA COURSE: Modify the program from this section so that the user can supply the interest rate. For very small interest rates, it may
INTRO JAVA COURSE: Modify the program from this section so that the user can supply the interest rate. For very small interest rates, it may take a very long time for the balance to double. Assume the user can't wait for more than twenty years. Stop adding interest when the balance has doubled or twenty years have elapsed.
import java.util.Scanner;
/** This program computes the time required to double an investment. */ public class DoubleInvestment { public static void main(String[] args) { final double INITIAL_BALANCE = 10000; final double TARGET = 2 * INITIAL_BALANCE; double balance = INITIAL_BALANCE; int year = 0;
Scanner in = new Scanner(System.in); System.out.print("Interest rate in percent: "); double rate = in.nextDouble();
// TODO: Stop when 20 years have elapsed
System.out.println("Year: " + year); System.out.println("Balance: " + balance); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
