Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write a java program, please write the program using comands in order to understan clearly A few students got together to form an investment group.

write a java program, please write the program using comands in order to understan clearly image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
A few students got together to form an investment group. They wanted to pool their savings and decide which investments would maximize their return. Each student was to find an investment, determine the interest (compounded annually, constant interest rate) then calculate the value (future value) of the initial investment over time, specifically for 5, 10, and 20 years. Each student was to report about the investment to the group; the group could then decide which investment(s) were most promising. You are one of the investors and decided that you would like to write a program that would calculate the future value of the investment given the interest and the principal. The formula for calculating the future value knowing interest and principal is: FV = P(1 + r)" Where: r: interest rate compounded annually (in the format.065 for 6.5%), P: principal In: number of years of investment | FV: future value after n years. Java InvestCalcApp class import java.util.*; import java.text public class InvestCalcApp! public static void main(String[] args) { Scanner input = new Scanner(System.in); double interest, principal; //vars for the interest rate and initial investment final Number Format DOLLAR FORMAT = Number Format.getCurrencyInstance(); //instantiate a default object of the Invest Calc class Invest Calc valuel - new Invest Calc(); System.out.println("Default InvestCalc Object"); System.out.println (valuel.toString 0 + " "); 1/query for interest and principal System.out.print("Enter an interest rate in decimal format: "); interest - input.nextDouble(); System.out.print("Enter the initial investment value: "); principal input, next Double(); // change object and output valuel.setRate (interest); valuel.set Principal (principal); System.out.println("Updated Invest Calc Object"); System.out.println(valuel.toString + " "); 7/test the futureValue and displayTable methods // UNCOMMENT THE NEXT TWO STATEMENTS WHEN YOU ARE READY TO TEST // System.out.println("Value after year DOLLAR FORMAT.format (valuel.futureValue (1)) + " "); valuel.displaytable(; //query for another interest and principal System.out.print("Enter another interest rate in decimal format: "); interest - input...nextDouble(); System.out.print("Enter another initial investment value: "); principal - input.nextDouble(); //instantiate an object of the InvestCale class InvestCale value2 - new Invest Calc(interest, principal): System.out.println("Non-Default InvestCalc Object"); System.out.println (value2.toString O+ " "); 77 UNCOMMENT THE NEXT STATEMENT WHEN YOU ARE READY TO TEST value2.displayTable(); Since the formula is standard and the group will be using this calculation repeatedly, you determine that instead of just solving the problem with just a single procedure, you decide to write an InvestCalc class. Create an InvestCalc class with the following (see InvestCalcApp.java code above for naming of methods): Declaration of instance variables for the interest rate and the principal, both real numbers, Constant class variables for short term (5 years), middle term (10 years) and long term (20 years) years (see displayTable () method), Constant class variables to format all dollars and percents (##0.00%) (see sample output), Constructors - default (zero for the interest rate and the principal) & non-default Accessors - returns values of the instance variables, a "public String toString()" method that displays the values of the instance variables, a "public double futureValue (int year)" method that uses the above formula to compute the future value, a "public void displayTable()" method that calculates and displays a table of the future values for 5, 10, and 20 years for the object (see sample output, Hint: you can use a "\t" as a tab to create columns.) To get started, create (new java file - copy/paste the code from the box above) the application (client) class InvestCalcApp.java. Then create a new java class file, InvestCalc.java, in the same directory. Then one at a time from the above list, add items to your class. Please test what you have completed up to the "toString" method first, then complete the last two methods. Here is some sample output using InvestCalcApp.java. Sample InvestCalcApp.java output: Default InvestCalc Object Principal: $0.00 Interest rate: 0.00% Enter an interest rate in decimal format: .05 Enter the initial investment value: 10000 Updated InvestCalc Object Principal: $10,000.00 Interest rate: 5.00% Value after 1 year $10,500.00 YEAR INTEREST RATE PRINCIPAL 5.00% $10,000.00 5.00% $10,000.00 5.00% $10,000.00 10 FUTURE VALUE $12,762.82 $16, 288.95 $26,532.98 20 Enter another interest rate in decimal format: .06 Enter another initial investment value: 8000 Non-Default InvestCalc Object Principal: $8,000.00 Interest rate: 6.00% YEAR INTEREST RATE 6.00% 6.00% 6.00% 10 PRINCIPAL $8,000.00 $8,000.00 $8,000.00 FUTURE VALUE $10,705.80 $14,326.78 $25,657.08 20 Press any key to continue .... Java InvestCalcApp class import java.util.*; import java.text.; public class InvestCalcApp public static void main(String[] args) { Scanner input = new Scanner(System.in); double interest, principal; //vars for the interest rate and initial investment final Number Format DOLLAR FORMAT - Number Format.getCurrency Instance(); //instantiate a default object of the InvestCalc class InvestCalc valuel-new Invest Calc(); System.out.println("Default Invest Calc Object"); System.out.println(valuel.toString 0 + " "); //query for interest and principal System.out.print("Enter an interest rate in decimal format: "); interest - input.nextDouble(); System.out.print("Enter the initial investment value: "); principal - input.nextDouble(); //change object and output valuel.setRate (interest); valuel.set Principal (principal); System.out.println("Updated Invest Calc Object"); System.out.println (valuel.toString() + " "); //test the futureValue and display Table methods // UNCOMMENT THE NEXT TWO STATEMENTS WHEN YOU ARE READY TO TEST // System.out.println("Value a fter 1 year DOLLAR FORMAT. format (valuel.futureValue (1)) + " "); valuel.display Table(); //query for another interest and principal System.out.print("Enter another interest rate in decimal format: "); interest - input.nextDouble(); System.out.print("Enter another initial investment value: "); principal - input.next Double(); //instantiate an object of the Invest Calc class Invest Calc value2 = new Invest Calc(interest, principal); System.out.println("Non-Default InvestCalc Object"); System.out.println (value2.toString() + " "); // UNCOMMENT THE NEXT STATEMENT WHEN YOU ARE READY TO TEST // value2.displayTable()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Semantics In Databases Second International Workshop Dagstuhl Castle Germany January 2001 Revised Papers Lncs 2582

Authors: Leopoldo Bertossi ,Gyula O.H. Katona ,Klaus-Dieter Schewe ,Bernhard Thalheim

2003rd Edition

3540009574, 978-3540009573

More Books

Students also viewed these Databases questions

Question

Explain the various methods of job evaluation

Answered: 1 week ago

Question

Differentiate Personnel Management and Human Resource Management

Answered: 1 week ago

Question

Describe the functions of Human resource management

Answered: 1 week ago