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

Assignment #2 Due date: 12:00 pm, 9/11/2017 Problem Description A monthly statem

ID: 3876893 • Letter: A

Question

Assignment #2

Due date: 12:00 pm, 9/11/2017

Problem Description

A monthly statement of a saving account usually includes the interest income and the ending balance of the account at the end of each month. Given the balance of an account at the end of a month, the interest income of the account can be calculated using the formula below:

Interest income = Account balance * Monthly interest rate (1)

The ending balance or the compound value of the account is computed using the formula below:

Ending balance = Account value + Interest income (2)

Combining the formula (1) and formula (2), the compound value of the account at the end of the first month can be calculated as:

Ending balance = Account value + (Account balance * Monthly interest rate)

Using a simple algebra rule, the above formula can be simplified as

1st Month ending balance = Account value * (1 + Monthly interest rate) (3)

If the customer of the account adds additional saving to the account each month, the account value should be the sum of the balance from the previous month and the saving added in the current month. Thus, the compound value of the account at the end of month 1 and forward is calculated by the following formula:

Ending balance = (Monthly saving + Previous month’s account value) * (1 + Monthly interest rate) (4)

Suppose you save $100 each month into a savings account with the annual interest rate 5%. Thus, the monthly interest rate is the annual interest rate divided by the number of months in a year, that is, 0.05/12 = 0.00417.

After the first month, the value in the account using the formula (3) becomes

100 * (1 + 0.00417) = 100.417

After the second month, the value in the account using formula (4) becomes

(100 + 100.417) * (1 + 0.00417) = 201.252

After the third month, the value in the account becomes

(100 + 201.252) * (1 + 0.00417) = 302.507

and so on.

This problem is to calculate the compound value of a saving account. Write a program that

Prompts the user to enter a monthly saving amount and the annual interest rate

Calculates and displays the compound value of the saving account after the 6th month.

Assignment Requirements

Use the exercise to practice the following problem solving steps:

Design a solution to the problem and identify the required process steps

Create a Java class to implement the solution and choose a proper class name

Write the solution pseudo-code as Java comments in the program

Use the pseudo-code comments as the guide and write Java code to implement the solution

Correct all syntax errors in the program

Run the program to correct all logical errors until it produces right answers

Perform the following three test runs:

Saving Amount

Annual Interest Rate

Compound Value after 6th Month

Test run 1

100

5.0

608.81

Test run 2

150

5.0

913.22

Test run 3

100

5.5

609.70

Saving Amount

Annual Interest Rate

Compound Value after 6th Month

Test run 1

100

5.0

608.81

Test run 2

150

5.0

913.22

Test run 3

100

5.5

609.70

Explanation / Answer

import java.util.Scanner;

public class CompoundInterest
{
double principal=0;
double annual_interest_rate=0;
double amount=0;

/**
This method computes the total amount in the account after six months
*/

public double amount_after_six_months(){
for(int month=1;month<=6;month++){
  
amount=(principal+amount)*(1+annual_interest_rate/1200);
}
return amount;
}

public static void main(String[] args)
{
//Instantiate the class
CompoundInterest ci = new CompoundInterest();
Scanner sc = new Scanner(System.in);
System.out.println("Please enter the monthly saving amount");
double principal = sc.nextDouble();
ci.principal=principal;
System.out.println("Please enter the annual interest rate");
double interest = sc.nextDouble();
ci.annual_interest_rate=interest;
System.out.println("Amount in the savings account after 6th month");
System.out.println(ci.amount_after_six_months());
}
}