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

Suppose we add $100 to a checking account in year 1, $200 in year 2, $300 in yea

ID: 3574882 • Letter: S

Question

Suppose we add $100 to a checking account in year 1, $200 in year 2, $300 in year 3, and so on. The account earns no interest. After how many years will the balance reach a given target? Modify the program below to produce the answer.

Complete the following file:

Investment.java

import java.util.Scanner;

/**
This program computes the time required to double an investment.
*/
public class Investment
{
public static void main(String[] args)
{
  
double balance = 0;
int year = . . .;

Scanner in = new Scanner(System.in);
System.out.print("Target: ");
double target = in.nextDouble();

// Add $100 in year 1, $200 in year 2, ..., until the
// target has been reached

while (. . .)
{
year++;
. . .
balance = balance + amount;
}
  
System.out.println("Year: " + year);
System.out.println("Balance: " + balance);
}
}

Explanation / Answer

public class Investment
{
    public static void main(String[] args)
    {
      
       double balance = 0;
       int year = 0;

      Scanner in = new Scanner(System.in);
       System.out.print("Target: ");
       double target = in.nextDouble();

      // Add $100 in year 1, $200 in year 2, ..., until the
       // target has been reached
      while (balance!=target)
       {
       year++;
        double amount = 100* year;
          
          balance = balance + amount;
       }
      
       System.out.println("Year: " + year);
       System.out.println("Balance: " + 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