Results 1 to 8 of 8
 09112012, 05:04 AM #1Member
 Join Date
 Sep 2012
 Posts
 4
 Rep Power
 0
Java Calculate Future Investment Amount
I do not know where I'm going wrong here. Pleaqse take a look and let me know what suggestions you have. Thank you. #So Frustrated
import java.util.Scanner;
public class FutureInvestment {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Autogenerated method stub
Scanner input = new Scanner(System.in);
//Obtain Investment Amount a
System.out.println("Enter investment amount: ");
double a = input.nextDouble();
//Obtain Interest Rate r
System.out.println("Enter interest rate: ");
double r = input.nextDouble();
//Obtain number of Years y
System.out.println("Enter number of years: ");
double y = input.nextDouble();
//Compute Future Investment Amount f
double f = a * Math.pow(1 + r, (y * 12));
//Display result
System.out.println("Accumulated value is " + f);
}
}
OUTPUT IS...........................
Enter investment amount:
1000
Enter interest rate:
.0425
Enter number of years:
1
Accumulated value is 1647.8313602236476
 09112012, 05:08 AM #2
Re: Java Calculate Future Investment Amount
We have no idea what is wrong unless you tell us. Are you getting incorrect output? Then you should post what you expect the output should be. If it is wrong then most likely your equation is incorrect. Where did you get it? Are you sure you entered it into your code correctly?
 09112012, 05:11 AM #3Member
 Join Date
 Sep 2012
 Posts
 4
 Rep Power
 0
Re: Java Calculate Future Investment Amount
Expected Output is:
Enter investment amount: 1000
Enter annual interest rate: 4.25
Enter number of years: 1
Accumulated value is 1043.34
Actual OUTPUT IS...........................
Enter investment amount: 1000
Enter interest rate: .0425
Enter number of years: 1
Accumulated value is 1647.8313602236476
 09112012, 05:32 AM #4Member
 Join Date
 Jul 2012
 Posts
 9
 Rep Power
 0
Re: Java Calculate Future Investment Amount
There is a difference between 4.25 and .0425 , please correct your input data and validate the output. If the equation you are using is correct then you should get the same output.
 09112012, 05:44 AM #5Member
 Join Date
 Sep 2012
 Posts
 4
 Rep Power
 0
Re: Java Calculate Future Investment Amount
Enter investment amount:
1000
Enter interest rate:
4.25
Enter number of years:
1
Accumulated value is 4.384414858452464E11
The r must be input .01...etc
 09112012, 06:45 AM #6Member
 Join Date
 Sep 2012
 Posts
 4
 Rep Power
 0
How do I do a Hard Truncate the output in this Java code after the second decimal?
Please help Me. My instructions are at the bottom.
import java.util.Scanner;
public class FutureInvestment {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Autogenerated method stub
Scanner input = new Scanner(System.in);
//Obtain Investment Amount a
System.out.println("Enter investment amount: ");
double a = input.nextDouble();
//Obtain Monthly Interest Rate r
System.out.println("Enter interest rate: ");
double r = input.nextDouble();
//Obtain number of Years y
System.out.println("Enter number of years: ");
double y = input.nextDouble();
double f = a * Math.pow(1 + (r/12),(y *12));
//Display result
System.out.println("Accumulated value is " + f);
}
}
OUTPUT IS
Enter investment amount: 1000
Enter interest rate: .0325
Enter number of years: 1
Accumulated value is 1032.9885118105894
I want it to say 1032.98
 09112012, 07:10 AM #7Moderator
 Join Date
 Feb 2009
 Location
 New Zealand
 Posts
 4,565
 Rep Power
 12
Re: How do I do a Hard Truncate the output in this Java code after the second decimal
Have a read of the options discussed in Oracle's Tutorial: Formatting Numeric Print Output (The Java™ Tutorials > Learning the Java Language > Numbers and Strings)
Accumulated value is 1032.9885118105894
I want it to say 1032.98
Java Code:import java.math.RoundingMode; import java.text.DecimalFormat; public class Test { public static void main(String[] args) { DecimalFormat fmt = new DecimalFormat(".000"); fmt.setRoundingMode(RoundingMode.DOWN); // prints 3.141 System.out.println(fmt.format(Math.PI)); } }
 09112012, 08:42 AM #8
Re: Java Calculate Future Investment Amount
Don't start a new thread for what is essentially a followon question, and moreover one which you already asked in the first thread. I've merged the two threads.
Please go through the following:
Forum Rules
Guide For New Members
BB Code List  Java Programming Forum
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
Similar Threads

Associate Conversion Program  European Investment Bank (Java)  Automated Trading
By ssinclair in forum Jobs OfferedReplies: 0Last Post: 05082012, 01:03 PM 
Java Developer Positions New York City (Investment Banking Domain)
By Dave IRIS in forum Jobs OfferedReplies: 0Last Post: 12282010, 05:08 PM 
Future of Java
By Skynet.Boy in forum New To JavaReplies: 0Last Post: 03062010, 06:16 PM 
Java is 15 years old  what is the Future?
By mikeVB in forum Jobs DiscussionReplies: 1Last Post: 03042010, 04:21 AM 
Future of Java ??
By DevzAbhi in forum Java SoftwareReplies: 16Last Post: 02262009, 10:34 PM
Bookmarks