Results 1 to 2 of 2
  1. #1
    lowpro is offline Member
    Join Date
    Nov 2007
    Location
    boston
    Posts
    10
    Rep Power
    0

    Unhappy need help checking monthlyRate entry

    how can i calculate the monthlyRate if user enter any #.exempl 9 or .09 or 15 or .15.rite now it works with any decimal and will give me the rite answer.how can i check for both #(allnumber and decimal) them calculate and get rite answer? i like to know thnks




    import java.util.Scanner;


    class C5E7experc{


    public static void main(String [] args){

    Scanner input = new Scanner(System.in);
    int years;
    double futureInvestementValue;
    double investmentAmount;
    double interestRate;
    double result;


    System.out.println(" enter amount invest:");
    investmentAmount = input.nextDouble();

    System.out.println(" enter monthly Rate ");
    interestRate = input.nextDouble();


    System.out.println("THE AMOUNT INVESTED IS:" + investmentAmount);
    System.out.println("THE ANNUAL INTEREST RATE IS:" + interestRate);
    System.out.println("YEARS\t\tFUTURE VALUE");
    for (int i = 1; i <= 30; ++i)
    {

    result = futureInvestmentValue( investmentAmount, interestRate/12, i);
    System.out.println(i + "\t\t" +"$" + result);
    /*
    * System.out.print(i + "\t"); //another way to format
    * Sytem.out.printf("$%8.2f" , result);
    * System.out.println(); */
    }// end for

    }//end main

    public static double futureInvestmentValue(double investmentAmount, double monthlyInterestRate, int years){

    double netInvestmentAmount;
    netInvestmentAmount = investmentAmount *
    Math.pow (1 + monthlyInterestRate, years * 12) ;
    netInvestmentAmount = (int) (netInvestmentAmount * 100) / 100.0;

    return netInvestmentAmount;
    } //end futureInvestmentValue


    }// end class

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
            System.out.println(" enter amount invest:");
            investmentAmount = input.nextDouble();
    //        investmentAmount = Double.parseDouble(input.nextLine());
    
            System.out.println(" enter monthly Rate ");
            if(input.hasNextInt())
                interestRate = input.nextDouble()/100.0;
            else
                interestRate = input.nextDouble();
    /*
            // Using nextLine here required it be used for investmentAmount.
            String line = input.nextLine();
            interestRate = Double.parseDouble(line);
            if(line.indexOf(".") == -1)
                interestRate /= 100.0;
    */

Similar Threads

  1. How to prevent duplicate username entry in database?
    By anki1234 in forum JavaServer Pages (JSP) and JSTL
    Replies: 4
    Last Post: 01-09-2008, 09:02 AM
  2. Duplicate entry in registration form!!!
    By anki1234 in forum Advanced Java
    Replies: 1
    Last Post: 01-04-2008, 09:15 PM
  3. checking if there are equal numbers
    By nalinda in forum New To Java
    Replies: 1
    Last Post: 11-18-2007, 07:21 AM
  4. checking if there are equal numbers
    By nalinda in forum New To Java
    Replies: 0
    Last Post: 11-18-2007, 03:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •