SlideShare uma empresa Scribd logo
1 de 4
Baixar para ler 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.

Mais conteúdo relacionado

Semelhante a 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
 

Semelhante a 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
 

Mais de 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
 

Mais de 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
 

Último

Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Food processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsFood processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsManeerUddin
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxleah joy valeriano
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 

Último (20)

Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Food processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsFood processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture hons
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 

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.