logo

Major Steps for Solving the Problem

Write a program that reads in investment amount, annual interest rate, and number of years, and displays the future investment value.

2 Pages528 Words11 Views
   

Added on  2022-08-21

Major Steps for Solving the Problem

Write a program that reads in investment amount, annual interest rate, and number of years, and displays the future investment value.

   Added on 2022-08-21

ShareRelated Documents
Design: (Describe the major steps for solving the problem.) 5 marks.
In the program, there are two methods one is for calculating the value of the future investment,
and another one is the main to calculate the future investment value. For this program, only
one .java file is created to perform calculations and used for taking user input. The main function
of this program calls a static method. The static method is for calculating the value of a future
investment based on user input. In this program, two double and one integer datatype variables
are used for user input.
Coding:
import java.util.Scanner;
public class FutureInvestmentValue {
public static void main(String[] args) {
// TODO Auto-generated method stub
double amount=0,rate=0;
int yr=0;
System.out.println("-----------------------------------");
System.out.println("Calculate Future Investment Value");
System.out.println("-----------------------------------");
Scanner sc=new Scanner(System.in);
System.out.println("Enter investment amount: ");
amount=sc.nextDouble();
System.out.println("Enter annual interest rate:");
rate=sc.nextDouble();
if(amount>0 && rate>0) {
rate=rate*0.01;
System.out.println("Number of years: ");
yr=sc.nextInt();
for(int i = 1; i <= yr; i++) {
double result=(futureInvestmentValue(amount, rate/12, i));
System.out.println("------------------------------------");
System.out.printf("Accumulated value is $"+"%.2f",result);
System.out.println();
System.out.println("-------------------------------------");
}
}else {
System.out.println("Invalid Input...!!");
}
}
public static double futureInvestmentValue(double investmentAmount,
double monthlyInterestRate, int years) {
Major Steps for Solving the Problem_1

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
Design: The First Step for Solving the Problem
|4
|439
|11

Introduction to Programming with Java - Solved Assignments
|12
|1129
|91

Task 2. 2.2 The main part of the program can use a FOR
|9
|750
|196

Program for Calculating Average of 1000 Grades
|3
|306
|22

Sales Commission Calculator
|11
|610
|80

Design Documentation Pseudo Code BEGIN Display Welcome message BEGIN
|13
|1512
|68