View Single Post
  #1 (permalink)  
Old 11-17-2007, 04:19 AM
lowpro lowpro is offline
Member
 
Join Date: Nov 2007
Location: boston
Posts: 10
lowpro is on a distinguished road
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
Reply With Quote
Sponsored Links