*
A friendly place for programming greenhorns!
Big Moose Saloon
Search

Java FAQ

Recent Topics

Flagged Topics

Hot Topics

Zero Replies
Register / Login
Win a copy of
Java 8 in Action
this week in the
Java 8
forum!
JavaRanch
»
Java Forums
»
Java
»
Beginning Java
Author
Future Value Calculator
Evan Cristofori
Greenhorn
Joined: Feb 02, 2007
Posts: 18
posted
Feb 12, 2007 16:37:00
0
Hi All,
I was wondering if someone could show me an example of a future value calculator:
" F = P(1+rate)^t "
where
F = future value
P = initial deposit (principal)
rate = (annual) interest rate (expressed as a fraction, e.g. 0.06)
t = number of years invested
Also,
The user needs to be able too input each parameter:
"Please input the principal: ______"
"Please input the annual interest rate: ______"
"Please input the number of years invested: ______"
Then,
The program should run the calculator and output the information:
"The future value of your investment after ___ years is : ______"
Thanks,
Evan
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
Feb 12, 2007 17:13:00
0
> I was wondering if someone could show me an example of a future value calculator:
if you are a beginner, have a crack at it yourself  you'll learn more that
way (the downside is you may end up with a few selfinflicted wounds!)
if you get stuck, post a specific question and include the code you've tried.
Evan Cristofori
Greenhorn
Joined: Feb 02, 2007
Posts: 18
posted
Feb 12, 2007 17:16:00
0
Hey,
I was going to... I just wanted to compare my results to someone elses.
Here is my code I came up with:
/** *The CompoundCalculatorApp class figures out the future value of an investment *after x years * *Author: Evan Cristofori *Date: 02/12/07 * */ import java.io.*; class CompoundCalculator { public static void main(String[] args) throws java.io.IOException { String s1, s2, s3; double p, r, f, rate; int t; InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); System.out.print("Please input the principal: "); s1 = br.readLine(); p = Double.parseDouble(s1); System.out.print("Please input the annual interest rate: "); s2 = br.readLine(); r = Double.parseDouble(s2); System.out.print("Please input the number of years invested: "); s3 = br.readLine(); t = Integer.parseInt(s3); rate = (1+r); f = p * Math.pow(rate, t); System.out.println("The future value of your investment after " + t + " years is: " + f); } }
How does it look?
Jesper de Jong
Java Cowboy
Saloon Keeper
Joined: Aug 16, 2005
Posts: 13884
10
I like...
posted
Feb 13, 2007 01:47:00
0
It looks good.
Java Beginners FAQ

JavaRanch SCJP FAQ

The Java Tutorial

Java SE 7 API documentation
Scala Notes
 My blog about Scala
It is sorta covered in the
JavaRanch Style Guide
.
subject: Future Value Calculator
Similar Threads
I can't see the error in this page
New to ArrayList
Use of Math.pow?
JSP
Did I do this right? (Interest calculator)
All times are in JavaRanch time: GMT6 in summer, GMT7 in winter