Results 1 to 2 of 2
- 11-17-2007, 02:19 AM #1
Member
- Join Date
- Nov 2007
- Location
- boston
- Posts
- 10
- Rep Power
- 0
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
- 11-17-2007, 05:15 AM #2
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
-
How to prevent duplicate username entry in database?
By anki1234 in forum JavaServer Pages (JSP) and JSTLReplies: 4Last Post: 01-09-2008, 08:02 AM -
Duplicate entry in registration form!!!
By anki1234 in forum Advanced JavaReplies: 1Last Post: 01-04-2008, 08:15 PM -
checking if there are equal numbers
By nalinda in forum New To JavaReplies: 1Last Post: 11-18-2007, 06:21 AM -
checking if there are equal numbers
By nalinda in forum New To JavaReplies: 0Last Post: 11-18-2007, 02:13 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks