SlideShare a Scribd company logo
1 of 4
Download to read offline
JAVA
Using the FutureValue.java file found here
(import java.util.Scanner;
import java.text.NumberFormat;
public class FutureValueApp {
public static void main(String[] args) {
System.out.println("Welcome to the Future Value Calculatorn");
Scanner sc = new Scanner(System.in);
String choice = "y";
while (choice.equalsIgnoreCase("y")) {
// get the input from the user
System.out.println("DATA ENTRY");
double monthlyInvestment = getDouble(sc,
"Enter monthly investment: ", 0, 1000);
double interestRate = getDouble(sc,
"Enter yearly interest rate: ", 0, 30);
int years = getInt(sc,
"Enter number of years: ", 0, 100);
System.out.println();
// calculate the future value
double futureValue = calculateFutureValue(
monthlyInvestment, interestRate, years);
// get the currency and percent formatters
NumberFormat c = NumberFormat.getCurrencyInstance();
NumberFormat p = NumberFormat.getPercentInstance();
p.setMinimumFractionDigits(1);
// format the result as a single string
String results
= "Monthly investment: " + c.format(monthlyInvestment) + "n"
+ "Yearly interest rate: " + p.format(interestRate / 100) + "n"
+ "Number of years: " + years + "n"
+ "Future value: " + c.format(futureValue) + "n";
// print the results
System.out.println("FORMATTED RESULTS");
System.out.println(results);
// see if the user wants to continue
System.out.print("Continue? (y/n): ");
choice = sc.nextLine();
System.out.println();
}
}
public static double getDouble(Scanner sc, String prompt) {
while (true) {
System.out.print(prompt);
try {
return Double.parseDouble(sc.nextLine());
} catch (NumberFormatException e) {
System.out.println("Error! Invalid decimal value.");
}
}
}
public static double getDouble(Scanner sc, String prompt,
double min, double max) {
while (true) {
double value = getdouble(sc, prompt)
if (value > min && value < max) {
return value;
} else {
System.out.println("Error! Number must be greater than " +
min + " and less than " + max + ".");
}
}
}
public static int getInt(Scanner sc, String prompt) {
while (true) {
System.out.print(prompt);
try {
return Integer.parseInt(sc.nextLine());
} catch (NumberFormatException e) {
System.out.println("Error! Invalid integer value.");
}
}
}
public static int getInt(Scanner sc, String prompt,
int min, int max) {
while (true) {
int value = getInt(sc, prompt);
if (value > min && value < max) {
return value;
} else {
System.out.println("Error! Number must be greater than " +
min + " and less than " + max + ".");
}
}
}
public static double calculateFutureValue(double monthlyInvestment,
double interestRate, int years) {
// convert yearly values to monthly values
double monthlyInterestRate = interestRate/12/100;
int months = years * 12;
double futureValue = 0.0;
for (int i = 0; i <= months; i++) {
futureValue = (futureValue + monthlyInvestment) *
(1 + monthlyInterestRate);
}
return futureValue;
}
}
)
application This exercise guides you through the process of using NetBeans or Eelipse to test and
debug an application. Test the Invoice application with invalid data 1. Use NetBeans or Eclipse to
open the ch06_ex1_Invoice project that's in the ex_starts directory. Then, test the Invoice
application with an invalid subtotal like $1000 (enter the dollar sign too). This should cause the
application to crash with a runtime error and to display an error message in the console. 2. Study
the error message. Then, note the line number of the statement in the InvoiceApp class that
caused the crash. 3. Click on the link to that line of code. This should open the Invoice.App.java
file in the code editor and highlight the line of code that caused the error. From this infomation,
determine the cause of the problem and fix it. Set a breakpoint and step through the application 4.
Set a breakpoint on this line of code: double dilacountpercent = awitch... Then, click on the Debug
button in the toolbar. This runs the project with the debugger on. 5. Display the console and enter
a value of 100 for the subtotal when prompted by the application. When you do, the application
runs to the breakpoint and stops. 6. Click the Variables tab to display the Variables window. Then,
note that the choice, customerType, and subtotal variables have been assigned values. 7. Press
the keyboard shortcut for the Step Into button (F7 in NetBeans, F5 in Eclipse) repeatedly to step
through the application one statement at a time. After each step, review the values in the Variables
window to see how they have changed. Note how the application steps through the switch
statement based on the customerType value and the if/else statements based on the subtotal
value. 8. As you continue stepping through the code, note that the IDE steps through the methods
of the Java API as well. Step through this code as much as you'd like. Then, click the Continue
(NetBeans) or Resume (Eclipse) button in the toolbar to continue the execution of the application.
9. Display the console again and enter " y " to continue. Then, enter a value of 50 for the subtotal.
10. Display the Variables window again and inspect the values of the variables.

More Related Content

Similar to Calculate Future Investment Value in Java

33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docxgilbertkpeters11344
 
CSC139 Chapter 9 Lab Assignments (1) Classes and Obj.docx
CSC139 Chapter 9 Lab Assignments (1) Classes and Obj.docxCSC139 Chapter 9 Lab Assignments (1) Classes and Obj.docx
CSC139 Chapter 9 Lab Assignments (1) Classes and Obj.docxruthannemcmullen
 
How React Native, Appium and me made each other shine @ContinuousDeliveryAmst...
How React Native, Appium and me made each other shine @ContinuousDeliveryAmst...How React Native, Appium and me made each other shine @ContinuousDeliveryAmst...
How React Native, Appium and me made each other shine @ContinuousDeliveryAmst...Wim Selles
 
Declarative presentations UIKonf
Declarative presentations UIKonfDeclarative presentations UIKonf
Declarative presentations UIKonfNataliya Patsovska
 
Advanced Computer Programming..pptx
Advanced Computer Programming..pptxAdvanced Computer Programming..pptx
Advanced Computer Programming..pptxKrishanthaRanaweera1
 
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docxransayo
 
This is a C# project . I am expected to create as this image shows. .pdf
This is a C# project . I am expected to create as this image shows. .pdfThis is a C# project . I am expected to create as this image shows. .pdf
This is a C# project . I am expected to create as this image shows. .pdfindiaartz
 
Informatics Practice Practical for 12th class
Informatics Practice Practical for 12th classInformatics Practice Practical for 12th class
Informatics Practice Practical for 12th classphultoosks876
 
Hi,I have updated the code as per your requirement. Highlighted th.pdf
Hi,I have updated the code as per your requirement. Highlighted th.pdfHi,I have updated the code as per your requirement. Highlighted th.pdf
Hi,I have updated the code as per your requirement. Highlighted th.pdfannaindustries
 
Java: Class Design Examples
Java: Class Design ExamplesJava: Class Design Examples
Java: Class Design ExamplesTareq Hasan
 
This project calls for the modification of the DollarFormat clas.pdf
This project calls for the modification of the DollarFormat clas.pdfThis project calls for the modification of the DollarFormat clas.pdf
This project calls for the modification of the DollarFormat clas.pdfjibinsh
 
srcCommissionCalculation.javasrcCommissionCalculation.javaimpo.docx
srcCommissionCalculation.javasrcCommissionCalculation.javaimpo.docxsrcCommissionCalculation.javasrcCommissionCalculation.javaimpo.docx
srcCommissionCalculation.javasrcCommissionCalculation.javaimpo.docxrafbolet0
 
Java Airline Reservation System – Travel Smarter, Not Harder.pdf
Java Airline Reservation System – Travel Smarter, Not Harder.pdfJava Airline Reservation System – Travel Smarter, Not Harder.pdf
Java Airline Reservation System – Travel Smarter, Not Harder.pdfSudhanshiBakre1
 
Mutation Analysis for JavaScript Web Applicaiton Testing SEKE2013
Mutation Analysis for JavaScript Web Applicaiton Testing  SEKE2013Mutation Analysis for JavaScript Web Applicaiton Testing  SEKE2013
Mutation Analysis for JavaScript Web Applicaiton Testing SEKE2013nkazuki
 
1-What are the opportunities and threats that could impact the org
1-What are the opportunities and threats that could impact the org1-What are the opportunities and threats that could impact the org
1-What are the opportunities and threats that could impact the orgAbbyWhyte974
 

Similar to Calculate Future Investment Value in Java (17)

33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
 
CSC139 Chapter 9 Lab Assignments (1) Classes and Obj.docx
CSC139 Chapter 9 Lab Assignments (1) Classes and Obj.docxCSC139 Chapter 9 Lab Assignments (1) Classes and Obj.docx
CSC139 Chapter 9 Lab Assignments (1) Classes and Obj.docx
 
How React Native, Appium and me made each other shine @ContinuousDeliveryAmst...
How React Native, Appium and me made each other shine @ContinuousDeliveryAmst...How React Native, Appium and me made each other shine @ContinuousDeliveryAmst...
How React Native, Appium and me made each other shine @ContinuousDeliveryAmst...
 
Declarative presentations UIKonf
Declarative presentations UIKonfDeclarative presentations UIKonf
Declarative presentations UIKonf
 
Advanced Computer Programming..pptx
Advanced Computer Programming..pptxAdvanced Computer Programming..pptx
Advanced Computer Programming..pptx
 
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
 
Day 5
Day 5Day 5
Day 5
 
PROGRAMMING QUESTIONS.docx
PROGRAMMING QUESTIONS.docxPROGRAMMING QUESTIONS.docx
PROGRAMMING QUESTIONS.docx
 
This is a C# project . I am expected to create as this image shows. .pdf
This is a C# project . I am expected to create as this image shows. .pdfThis is a C# project . I am expected to create as this image shows. .pdf
This is a C# project . I am expected to create as this image shows. .pdf
 
Informatics Practice Practical for 12th class
Informatics Practice Practical for 12th classInformatics Practice Practical for 12th class
Informatics Practice Practical for 12th class
 
Hi,I have updated the code as per your requirement. Highlighted th.pdf
Hi,I have updated the code as per your requirement. Highlighted th.pdfHi,I have updated the code as per your requirement. Highlighted th.pdf
Hi,I have updated the code as per your requirement. Highlighted th.pdf
 
Java: Class Design Examples
Java: Class Design ExamplesJava: Class Design Examples
Java: Class Design Examples
 
This project calls for the modification of the DollarFormat clas.pdf
This project calls for the modification of the DollarFormat clas.pdfThis project calls for the modification of the DollarFormat clas.pdf
This project calls for the modification of the DollarFormat clas.pdf
 
srcCommissionCalculation.javasrcCommissionCalculation.javaimpo.docx
srcCommissionCalculation.javasrcCommissionCalculation.javaimpo.docxsrcCommissionCalculation.javasrcCommissionCalculation.javaimpo.docx
srcCommissionCalculation.javasrcCommissionCalculation.javaimpo.docx
 
Java Airline Reservation System – Travel Smarter, Not Harder.pdf
Java Airline Reservation System – Travel Smarter, Not Harder.pdfJava Airline Reservation System – Travel Smarter, Not Harder.pdf
Java Airline Reservation System – Travel Smarter, Not Harder.pdf
 
Mutation Analysis for JavaScript Web Applicaiton Testing SEKE2013
Mutation Analysis for JavaScript Web Applicaiton Testing  SEKE2013Mutation Analysis for JavaScript Web Applicaiton Testing  SEKE2013
Mutation Analysis for JavaScript Web Applicaiton Testing SEKE2013
 
1-What are the opportunities and threats that could impact the org
1-What are the opportunities and threats that could impact the org1-What are the opportunities and threats that could impact the org
1-What are the opportunities and threats that could impact the org
 

More from adinathassociates

It is somewhat curious that this documentation does not wind.pdf
It is somewhat curious that this documentation does not wind.pdfIt is somewhat curious that this documentation does not wind.pdf
It is somewhat curious that this documentation does not wind.pdfadinathassociates
 
izgi ynteminin ve nceden alanm plakann sonularna gre k.pdf
izgi ynteminin ve nceden alanm plakann sonularna gre k.pdfizgi ynteminin ve nceden alanm plakann sonularna gre k.pdf
izgi ynteminin ve nceden alanm plakann sonularna gre k.pdfadinathassociates
 
Jamie needs a new roof on her house The cash cost is 4100.pdf
Jamie needs a new roof on her house The cash cost is 4100.pdfJamie needs a new roof on her house The cash cost is 4100.pdf
Jamie needs a new roof on her house The cash cost is 4100.pdfadinathassociates
 
It is necessary for Marketers to know how the customers feel.pdf
It is necessary for Marketers to know how the customers feel.pdfIt is necessary for Marketers to know how the customers feel.pdf
It is necessary for Marketers to know how the customers feel.pdfadinathassociates
 
James tiene la enfermedad celaca Cul de los siguientes a.pdf
James tiene la enfermedad celaca Cul de los siguientes a.pdfJames tiene la enfermedad celaca Cul de los siguientes a.pdf
James tiene la enfermedad celaca Cul de los siguientes a.pdfadinathassociates
 
It is difficult to quantify a value for certain biological a.pdf
It is difficult to quantify a value for certain biological a.pdfIt is difficult to quantify a value for certain biological a.pdf
It is difficult to quantify a value for certain biological a.pdfadinathassociates
 
It was leaked that Bergdorf Goodman treated Kayla a Hispanic.pdf
It was leaked that Bergdorf Goodman treated Kayla a Hispanic.pdfIt was leaked that Bergdorf Goodman treated Kayla a Hispanic.pdf
It was leaked that Bergdorf Goodman treated Kayla a Hispanic.pdfadinathassociates
 
It is possible to create dynamic GUI applications based on c.pdf
It is possible to create dynamic GUI applications based on c.pdfIt is possible to create dynamic GUI applications based on c.pdf
It is possible to create dynamic GUI applications based on c.pdfadinathassociates
 
Joe makes annual income of 5000 for five years Joe withdr.pdf
Joe makes annual income of 5000 for five years Joe withdr.pdfJoe makes annual income of 5000 for five years Joe withdr.pdf
Joe makes annual income of 5000 for five years Joe withdr.pdfadinathassociates
 
Joan Robinson ktisat okumann amac iktisat sorularna bir d.pdf
Joan Robinson ktisat okumann amac iktisat sorularna bir d.pdfJoan Robinson ktisat okumann amac iktisat sorularna bir d.pdf
Joan Robinson ktisat okumann amac iktisat sorularna bir d.pdfadinathassociates
 
Jobyde ie alma ilerleme terfi ve tevik etme grevleri gen.pdf
Jobyde ie alma ilerleme terfi ve tevik etme grevleri gen.pdfJobyde ie alma ilerleme terfi ve tevik etme grevleri gen.pdf
Jobyde ie alma ilerleme terfi ve tevik etme grevleri gen.pdfadinathassociates
 
It is not option 3 please help What would be the outcome of.pdf
It is not option 3 please help What would be the outcome of.pdfIt is not option 3 please help What would be the outcome of.pdf
It is not option 3 please help What would be the outcome of.pdfadinathassociates
 
Joanna and Chip Gaines and Michael Dubin got together recent.pdf
Joanna and Chip Gaines and Michael Dubin got together recent.pdfJoanna and Chip Gaines and Michael Dubin got together recent.pdf
Joanna and Chip Gaines and Michael Dubin got together recent.pdfadinathassociates
 
JKL Co issues zero coupon bonds on the market at a price of.pdf
JKL Co issues zero coupon bonds on the market at a price of.pdfJKL Co issues zero coupon bonds on the market at a price of.pdf
JKL Co issues zero coupon bonds on the market at a price of.pdfadinathassociates
 
Jill is offered a choice between receiving 50 with certaint.pdf
Jill is offered a choice between receiving 50 with certaint.pdfJill is offered a choice between receiving 50 with certaint.pdf
Jill is offered a choice between receiving 50 with certaint.pdfadinathassociates
 
Jennys Froyo INC Balance Sheet For Year Ended December 31.pdf
Jennys Froyo INC Balance Sheet For Year Ended December 31.pdfJennys Froyo INC Balance Sheet For Year Ended December 31.pdf
Jennys Froyo INC Balance Sheet For Year Ended December 31.pdfadinathassociates
 
Jim y Sue se iban a casar y estaban muy enamorados Antes de.pdf
Jim y Sue se iban a casar y estaban muy enamorados Antes de.pdfJim y Sue se iban a casar y estaban muy enamorados Antes de.pdf
Jim y Sue se iban a casar y estaban muy enamorados Antes de.pdfadinathassociates
 
Jhania Bive the muk hroutwes ite p+4i if peras bt in +45 te.pdf
Jhania Bive the muk hroutwes ite p+4i if peras bt in +45 te.pdfJhania Bive the muk hroutwes ite p+4i if peras bt in +45 te.pdf
Jhania Bive the muk hroutwes ite p+4i if peras bt in +45 te.pdfadinathassociates
 
JAVA Please help me on this method The requirement of the m.pdf
JAVA Please help me on this method The requirement of the m.pdfJAVA Please help me on this method The requirement of the m.pdf
JAVA Please help me on this method The requirement of the m.pdfadinathassociates
 
Jennifer invested the profit of his business in an investmen.pdf
Jennifer invested the profit of his business in an investmen.pdfJennifer invested the profit of his business in an investmen.pdf
Jennifer invested the profit of his business in an investmen.pdfadinathassociates
 

More from adinathassociates (20)

It is somewhat curious that this documentation does not wind.pdf
It is somewhat curious that this documentation does not wind.pdfIt is somewhat curious that this documentation does not wind.pdf
It is somewhat curious that this documentation does not wind.pdf
 
izgi ynteminin ve nceden alanm plakann sonularna gre k.pdf
izgi ynteminin ve nceden alanm plakann sonularna gre k.pdfizgi ynteminin ve nceden alanm plakann sonularna gre k.pdf
izgi ynteminin ve nceden alanm plakann sonularna gre k.pdf
 
Jamie needs a new roof on her house The cash cost is 4100.pdf
Jamie needs a new roof on her house The cash cost is 4100.pdfJamie needs a new roof on her house The cash cost is 4100.pdf
Jamie needs a new roof on her house The cash cost is 4100.pdf
 
It is necessary for Marketers to know how the customers feel.pdf
It is necessary for Marketers to know how the customers feel.pdfIt is necessary for Marketers to know how the customers feel.pdf
It is necessary for Marketers to know how the customers feel.pdf
 
James tiene la enfermedad celaca Cul de los siguientes a.pdf
James tiene la enfermedad celaca Cul de los siguientes a.pdfJames tiene la enfermedad celaca Cul de los siguientes a.pdf
James tiene la enfermedad celaca Cul de los siguientes a.pdf
 
It is difficult to quantify a value for certain biological a.pdf
It is difficult to quantify a value for certain biological a.pdfIt is difficult to quantify a value for certain biological a.pdf
It is difficult to quantify a value for certain biological a.pdf
 
It was leaked that Bergdorf Goodman treated Kayla a Hispanic.pdf
It was leaked that Bergdorf Goodman treated Kayla a Hispanic.pdfIt was leaked that Bergdorf Goodman treated Kayla a Hispanic.pdf
It was leaked that Bergdorf Goodman treated Kayla a Hispanic.pdf
 
It is possible to create dynamic GUI applications based on c.pdf
It is possible to create dynamic GUI applications based on c.pdfIt is possible to create dynamic GUI applications based on c.pdf
It is possible to create dynamic GUI applications based on c.pdf
 
Joe makes annual income of 5000 for five years Joe withdr.pdf
Joe makes annual income of 5000 for five years Joe withdr.pdfJoe makes annual income of 5000 for five years Joe withdr.pdf
Joe makes annual income of 5000 for five years Joe withdr.pdf
 
Joan Robinson ktisat okumann amac iktisat sorularna bir d.pdf
Joan Robinson ktisat okumann amac iktisat sorularna bir d.pdfJoan Robinson ktisat okumann amac iktisat sorularna bir d.pdf
Joan Robinson ktisat okumann amac iktisat sorularna bir d.pdf
 
Jobyde ie alma ilerleme terfi ve tevik etme grevleri gen.pdf
Jobyde ie alma ilerleme terfi ve tevik etme grevleri gen.pdfJobyde ie alma ilerleme terfi ve tevik etme grevleri gen.pdf
Jobyde ie alma ilerleme terfi ve tevik etme grevleri gen.pdf
 
It is not option 3 please help What would be the outcome of.pdf
It is not option 3 please help What would be the outcome of.pdfIt is not option 3 please help What would be the outcome of.pdf
It is not option 3 please help What would be the outcome of.pdf
 
Joanna and Chip Gaines and Michael Dubin got together recent.pdf
Joanna and Chip Gaines and Michael Dubin got together recent.pdfJoanna and Chip Gaines and Michael Dubin got together recent.pdf
Joanna and Chip Gaines and Michael Dubin got together recent.pdf
 
JKL Co issues zero coupon bonds on the market at a price of.pdf
JKL Co issues zero coupon bonds on the market at a price of.pdfJKL Co issues zero coupon bonds on the market at a price of.pdf
JKL Co issues zero coupon bonds on the market at a price of.pdf
 
Jill is offered a choice between receiving 50 with certaint.pdf
Jill is offered a choice between receiving 50 with certaint.pdfJill is offered a choice between receiving 50 with certaint.pdf
Jill is offered a choice between receiving 50 with certaint.pdf
 
Jennys Froyo INC Balance Sheet For Year Ended December 31.pdf
Jennys Froyo INC Balance Sheet For Year Ended December 31.pdfJennys Froyo INC Balance Sheet For Year Ended December 31.pdf
Jennys Froyo INC Balance Sheet For Year Ended December 31.pdf
 
Jim y Sue se iban a casar y estaban muy enamorados Antes de.pdf
Jim y Sue se iban a casar y estaban muy enamorados Antes de.pdfJim y Sue se iban a casar y estaban muy enamorados Antes de.pdf
Jim y Sue se iban a casar y estaban muy enamorados Antes de.pdf
 
Jhania Bive the muk hroutwes ite p+4i if peras bt in +45 te.pdf
Jhania Bive the muk hroutwes ite p+4i if peras bt in +45 te.pdfJhania Bive the muk hroutwes ite p+4i if peras bt in +45 te.pdf
Jhania Bive the muk hroutwes ite p+4i if peras bt in +45 te.pdf
 
JAVA Please help me on this method The requirement of the m.pdf
JAVA Please help me on this method The requirement of the m.pdfJAVA Please help me on this method The requirement of the m.pdf
JAVA Please help me on this method The requirement of the m.pdf
 
Jennifer invested the profit of his business in an investmen.pdf
Jennifer invested the profit of his business in an investmen.pdfJennifer invested the profit of his business in an investmen.pdf
Jennifer invested the profit of his business in an investmen.pdf
 

Recently uploaded

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 

Recently uploaded (20)

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 

Calculate Future Investment Value in Java

  • 1. JAVA Using the FutureValue.java file found here (import java.util.Scanner; import java.text.NumberFormat; public class FutureValueApp { public static void main(String[] args) { System.out.println("Welcome to the Future Value Calculatorn"); Scanner sc = new Scanner(System.in); String choice = "y"; while (choice.equalsIgnoreCase("y")) { // get the input from the user System.out.println("DATA ENTRY"); double monthlyInvestment = getDouble(sc, "Enter monthly investment: ", 0, 1000); double interestRate = getDouble(sc, "Enter yearly interest rate: ", 0, 30); int years = getInt(sc, "Enter number of years: ", 0, 100); System.out.println(); // calculate the future value double futureValue = calculateFutureValue( monthlyInvestment, interestRate, years); // get the currency and percent formatters NumberFormat c = NumberFormat.getCurrencyInstance(); NumberFormat p = NumberFormat.getPercentInstance(); p.setMinimumFractionDigits(1); // format the result as a single string String results = "Monthly investment: " + c.format(monthlyInvestment) + "n" + "Yearly interest rate: " + p.format(interestRate / 100) + "n" + "Number of years: " + years + "n" + "Future value: " + c.format(futureValue) + "n"; // print the results System.out.println("FORMATTED RESULTS"); System.out.println(results); // see if the user wants to continue System.out.print("Continue? (y/n): "); choice = sc.nextLine(); System.out.println(); } }
  • 2. public static double getDouble(Scanner sc, String prompt) { while (true) { System.out.print(prompt); try { return Double.parseDouble(sc.nextLine()); } catch (NumberFormatException e) { System.out.println("Error! Invalid decimal value."); } } } public static double getDouble(Scanner sc, String prompt, double min, double max) { while (true) { double value = getdouble(sc, prompt) if (value > min && value < max) { return value; } else { System.out.println("Error! Number must be greater than " + min + " and less than " + max + "."); } } } public static int getInt(Scanner sc, String prompt) { while (true) { System.out.print(prompt); try { return Integer.parseInt(sc.nextLine()); } catch (NumberFormatException e) { System.out.println("Error! Invalid integer value."); } } } public static int getInt(Scanner sc, String prompt, int min, int max) { while (true) { int value = getInt(sc, prompt); if (value > min && value < max) { return value; } else { System.out.println("Error! Number must be greater than " +
  • 3. min + " and less than " + max + "."); } } } public static double calculateFutureValue(double monthlyInvestment, double interestRate, int years) { // convert yearly values to monthly values double monthlyInterestRate = interestRate/12/100; int months = years * 12; double futureValue = 0.0; for (int i = 0; i <= months; i++) { futureValue = (futureValue + monthlyInvestment) * (1 + monthlyInterestRate); } return futureValue; } } ) application This exercise guides you through the process of using NetBeans or Eelipse to test and debug an application. Test the Invoice application with invalid data 1. Use NetBeans or Eclipse to open the ch06_ex1_Invoice project that's in the ex_starts directory. Then, test the Invoice application with an invalid subtotal like $1000 (enter the dollar sign too). This should cause the application to crash with a runtime error and to display an error message in the console. 2. Study the error message. Then, note the line number of the statement in the InvoiceApp class that caused the crash. 3. Click on the link to that line of code. This should open the Invoice.App.java file in the code editor and highlight the line of code that caused the error. From this infomation, determine the cause of the problem and fix it. Set a breakpoint and step through the application 4. Set a breakpoint on this line of code: double dilacountpercent = awitch... Then, click on the Debug button in the toolbar. This runs the project with the debugger on. 5. Display the console and enter a value of 100 for the subtotal when prompted by the application. When you do, the application runs to the breakpoint and stops. 6. Click the Variables tab to display the Variables window. Then, note that the choice, customerType, and subtotal variables have been assigned values. 7. Press the keyboard shortcut for the Step Into button (F7 in NetBeans, F5 in Eclipse) repeatedly to step through the application one statement at a time. After each step, review the values in the Variables window to see how they have changed. Note how the application steps through the switch statement based on the customerType value and the if/else statements based on the subtotal value. 8. As you continue stepping through the code, note that the IDE steps through the methods of the Java API as well. Step through this code as much as you'd like. Then, click the Continue (NetBeans) or Resume (Eclipse) button in the toolbar to continue the execution of the application. 9. Display the console again and enter " y " to continue. Then, enter a value of 50 for the subtotal.
  • 4. 10. Display the Variables window again and inspect the values of the variables.