MITS4002 Activity 03: Calculating Future Investment Value using Java

Verified

Added on  2025/04/28

|4
|393
|145
AI Summary
Desklib provides past papers and solved assignments for students. This project demonstrates calculating future investment value using Java.
Document Page
MITS4002
OBJECT-ORIENTED SOFTWARE
DEVELOPMENT
Activity 03
Project: Calculating Future Investment Value
Student ID:
Student full name:
Total Points (20 pts):
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
MITS4002 Activity 03
Table of Contents
Analysis...........................................................................................................................................
Design..............................................................................................................................................
Coding..............................................................................................................................................
Output screenshot............................................................................................................................
Testing.............................................................................................................................................
Copyright © 2015-2019 VIT, All Rights Reserved. Page 2
Document Page
MITS4002 Activity 03
Analysis: The given problem needs us to write a program which will calculate the future
investment value. The input for the program will be investment amount, annual interest rate, and
number of years which will be taken from the user. On the basis of this input, the program will
calculate the value of the future investment value based on the provided formula and will display
the result as output.
Design:
a) The formula was roughly written in code format i.e. in a way easily understood and
correctly interpreted by the program.
b) This created formula of future investment was placed in a function with three arguments.
c) This function was called in the main class and the arguments for the function were the
input values taken from the user.
d) These input values were taken using a scanner class object.
e) The program was built such that it could handle exceptions.
Coding:
import java.util.Scanner;
import java.util.InputMismatchException;
public class InvestmentValue {
//Function for calculating future investment value
public static void futureInvestmentValue(double amount, double rate, int
years) {
double temp= amount * Math.pow((1+rate/100),years);
System.out.println(temp);
}
public static void main (String[] args) {
try {
@SuppressWarnings("resource")
Scanner scan= new Scanner (System.in);
System.out.println("Enter investment amount: ");
double amount= scan.nextDouble();
System.out.println("Enter interest rate in percentage (%): ");
double rt= scan.nextDouble();
System.out.println("Enter number of years: ");
int yrs=scan.nextInt();
System.out.println("Accumulated value is: ");
futureInvestmentValue(amount, rt, yrs); //Passing user input as arguments
to the function
Copyright © 2015-2019 VIT, All Rights Reserved. Page 3
Document Page
MITS4002 Activity 03
}
catch (InputMismatchException e) {
System.out.println("Input should only be numerical");
main(null);
}
catch (Exception e) {
System.out.println(e);
main(null);
}
}
}
Output screenshot:
Figure 1: Program output
Testing: The program was given invalid values such as string and the program asked to enter
the value in the correct format. The correct values were given and the program calculated the
correct future investment value. All three values were given in incorrect datatypes and the
program did not crash and exit, it showed the exception and asked to enter values in correct
format.
Copyright © 2015-2019 VIT, All Rights Reserved. Page 4
chevron_up_icon
1 out of 4
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]