Let's 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. 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27     finaldoubleTARGET=2*INITIAL_BALANCE;   doublebalance=INITIAL_BALANCE; intyear=0;   Scannerin=newScanner(System.in); System.out.print("Interest rate in percent: "); doublerate=in.nextDouble();   // TODO: Count the years required for the investment to double // but no more than 20 years   /* Your code goes here */   System.out.println("Year: "+year); System.out.printf("Balance: %.2f%n", balance); }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Let's 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.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 
 
finaldoubleTARGET=2*INITIAL_BALANCE;
 
doublebalance=INITIAL_BALANCE;
intyear=0;
 
Scannerin=newScanner(System.in);
System.out.print("Interest rate in percent: ");
doublerate=in.nextDouble();
 
// TODO: Count the years required for the investment to double
// but no more than 20 years
 
/* Your code goes here */
 
System.out.println("Year: "+year);
System.out.printf("Balance: %.2f%n", balance);
}
 
 
 
The image presents a task for modifying a program to allow a user to input an interest rate. The program calculates how long it will take for an initial balance to double, but stops after 20 years if the balance hasn't doubled.

Here's the detailed breakdown of the code snippet provided:

```java
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: Count the years required for the investment to double
// but no more than 20 years

/* Your code goes here */

System.out.println("Year: " + year);
System.out.printf("Balance: %.2f%n", balance);
```

- **Line 1-2:** Initializes the balance to `INITIAL_BALANCE` and the year counter to 0.
- **Line 4:** Sets up a `Scanner` to take input from the user.
- **Line 5:** Prompts the user to enter the interest rate in percent.
- **Line 6:** Captures the input rate as a `double`.
- **Line 9-10:** Placeholder for the logic to calculate the number of years it will take for the balance to double, but not exceeding 20 years.
- **Line 12:** Placeholder comment indicating where additional code is to be inserted.
- **Line 14-15:** Outputs the year and current balance.

The program's objective is to use a loop (not shown) to apply the interest rate to the balance annually, increasing the year counter each iteration. The loop should terminate when the balance doubles or 20 years have passed, and then print the final year and balance.
Transcribed Image Text:The image presents a task for modifying a program to allow a user to input an interest rate. The program calculates how long it will take for an initial balance to double, but stops after 20 years if the balance hasn't doubled. Here's the detailed breakdown of the code snippet provided: ```java 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: Count the years required for the investment to double // but no more than 20 years /* Your code goes here */ System.out.println("Year: " + year); System.out.printf("Balance: %.2f%n", balance); ``` - **Line 1-2:** Initializes the balance to `INITIAL_BALANCE` and the year counter to 0. - **Line 4:** Sets up a `Scanner` to take input from the user. - **Line 5:** Prompts the user to enter the interest rate in percent. - **Line 6:** Captures the input rate as a `double`. - **Line 9-10:** Placeholder for the logic to calculate the number of years it will take for the balance to double, but not exceeding 20 years. - **Line 12:** Placeholder comment indicating where additional code is to be inserted. - **Line 14-15:** Outputs the year and current balance. The program's objective is to use a loop (not shown) to apply the interest rate to the balance annually, increasing the year counter each iteration. The loop should terminate when the balance doubles or 20 years have passed, and then print the final year and balance.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education