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

(Please write notepad style) Write a program that reads three values from the ke

ID: 643571 • Letter: #

Question

(Please write notepad style)

Write a program that reads three values from the keyboard using the JOptionPane class representing, respectively, an investors name, an investment amount, and an interest rate (you will expect the user to enter a number such as .065 for the interest rate, representing a 6.5% interest rate). Your program should calculate and output (in currency notation) the future value of the investment in 5, 10, and 20 years using the following formula:

Future value = investment(1 + interest rate)year

We will assume that the interest rate is an annual rate and is compounded annually. Use the JOptionPane class for the output.

Explanation / Answer

import javax.swing.*;
public class Addition {
public static void main ( String args[] )
{
String name, //first string entered by user for nme
amount, // second string entered by user for amount
rate; // third string entered by user intrest rate

int number1, // first number to add
number2, //second number to add
sum[]= new int[3] ; //sum of number1 and number2

//read in the first number from user as a string
name =
JOptionPane.showInputDialog ( "Enter invester name" );

//read in the second number from user as a string
amount =
JOptionPane.showInputDialog ( "Enter investment amount" );
rate =
JOptionPane.showInputDialog ( "Enter investment amount" );

  
  


number1 = Integer.parseInt (amount);
number2 = Integer.parseInt (rate);
int year[]= new int[3];
year[0]=5;
year[1]=10;
year[2]=20;
for (int i =0;i<3;i++)
{
sum[i] = number1*(1 + number2)*year[i];
}

//display the results
JOptionPane.showMessageDialog (
null, "The future value for 5 " + sum[0], "Results",
JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog (
null, "The future value for 10 " + sum[1], "Results",
JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog (
null, "The future value for 20 " + sum[2], "Results",
JOptionPane.PLAIN_MESSAGE);
System.exit ( 0 ); //ends the program
}
}