MITS4002 Activity 03: Calculating Future Investment Value using Java

Verified

Added on  2025/04/28

|5
|522
|205
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
Copyright © 2015-2019 VIT, All Rights Reserved. Page 2
Document Page
MITS4002 Activity 03
A. Analysis: ~ We must write a program that calculates the future value of the investment.
The amount for investment, the annual interest rate and the number of years taken from
the user will be the input to the program. The program calculates the value on the basis of
the formula provided and shows the output of the future investment value based on that
input.
B. Design: ~
1. The first step will be declaring all the variables which will be used in the formula
for future investment.
2. A function will be created for future investment as an output. The formula will be
replaced with the variables and the final value will be calculated.
3. To scan the input, scanner class will be imported and then the user will be able to
input and that input will be taken and used in the formula.
4. If there is a wrong entry by the user, an exception handling will be implemented so
that the program continues to run even if there is an error with a message.
5. As soon as the exception is handled properly, the program returns to the main
function.
C. Coding: ~
import java.util.InputMismatchException;
import java.util.Scanner;
public class activity03program
{
static double inv_amt; //Amount of Investment
static double int_rate;// Rate of interest
static int total_years;//total total_years
static double value_fut_inv=0.0; //final value of the future
investment
Copyright © 2015-2019 VIT, All Rights Reserved. Page 3
Document Page
MITS4002 Activity 03
public static void final_value(double inv_amt, double int_rate, int
total_years)
{
double fut_inv_val= inv_amt *
Math.pow((1+int_rate/100),total_years);
System.out.println(fut_inv_val); // future investment value
printed.
}
public static void main (String[] args)
{
try
{
Scanner ob= new Scanner (System.in);
System.out.println("Amount of Investment = ");
double amtt= ob.nextDouble();
System.out.println("rate of interest = ");
double rate_int= ob.nextDouble();
System.out.println("no. of years = ");
int yrs=ob.nextInt();
System.out.println("Value of future investment = ");
final_value(amtt, rate_int, yrs);
}
catch (InputMismatchException e)
{
System.out.println("Enter numerical only.");
main(null);
}
catch (Exception e)
Copyright © 2015-2019 VIT, All Rights Reserved. Page 4
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
{
System.out.println(e);
main(null);
}}}
D. Output screenshot: ~
Figure 1: output 1
Figure 2: output 2
E. Testing: ~ For this process we will be testing each functionality as well as correct
datatype.
1. Checking the investment amount variable, enter a value and then check if the
datatype is right or not. If the data type is not right then the program will return to
the main function with an exception message. If the value is right then the
program continues.
2. Similarly, all the variables will be tested and then if it’s of correct datatype
program will run without any exception but if the incorrect datatype is there then
the program will give an exception and will return to the main function.
3. Finally, testing the future investment returning function. All the variables and
values will be passed to the function and the calculation of the output will be
completed with the printing on the console.
Copyright © 2015-2019 VIT, All Rights Reserved. Page 5
chevron_up_icon
1 out of 5
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]