Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Present Value

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    6
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Present Value

    import java.util.Scanner;
    import java.text.DecimalFormat;
     
    public class PresentValue
    {
       public static void main(String[] args)
       {
          Scanner keyboard = new Scanner(System.in);
          DecimalFormat num = new DecimalFormat("#,###.00");
          double present = 0.0, annualRate = 0.0, future = 0.0, numberOfYears = 0.0;
     
          System.out.print("Enter the future value: ");
          future = keyboard.nextDouble();
     
          System.out.print("Enter annual interest rate (in decimal point, not percent): ");
          annualRate = keyboard.nextDouble();
     
          System.out.print("Enter the number of years: ");
          numberOfYears = keyboard.nextDouble();
     
          present = presentValue(future, present, annualRate, numberOfYears);
          System.out.print("Present value must be: $" + num.format(present));
       }
       public static double presentValue(double f, double p, double r, double n)
       {      
          p = f/Math.pow(1 + r, n);
          return p;
       }
    }

    If the user were to enter 2.5 for the annual interest rate, how can I make sure it changes it to .025 instead of having to ask the user to enter in decimals and not percent?
    Last edited by rosiems95; April 3rd, 2014 at 10:06 PM.


  2. #2
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    285
    My Mood
    Amused
    Thanks
    6
    Thanked 64 Times in 61 Posts

    Default Re: Present Value

    this is a Math question. Try to open you math books in grade school, or try to do an internet search about rates/percentage.

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,308
    My Mood
    Mellow
    Thanks
    194
    Thanked 669 Times in 656 Posts

    Default Re: Present Value

    Or, it's an input validation/modification question. Determine the scale of the value input by the user and modify it appropriately for the equation being used - and that's back to the math question.

Similar Threads

  1. How to hyphanate phrase which is present in database
    By pratik.a03 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 17th, 2014, 04:36 AM
  2. How to hyphanate phrase which is present in database
    By pratik.a03 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 17th, 2014, 03:47 AM
  3. logic present tag
    By naval.gupta4u@gmail.com in forum Java Servlet
    Replies: 0
    Last Post: July 15th, 2012, 01:28 AM