Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-17-2007, 04:19 AM
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-17-2007, 07:15 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
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; */
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Checking if Session is new JavaForums Java Blogs 0 03-31-2008 06:50 PM
How to prevent duplicate username entry in database? anki1234 JavaServer Pages (JSP) and JSTL 4 01-09-2008 10:02 AM
Duplicate entry in registration form!!! anki1234 Advanced Java 1 01-04-2008 10:15 PM
checking if there are equal numbers nalinda New To Java 1 11-18-2007 08:21 AM
checking if there are equal numbers nalinda New To Java 0 11-18-2007 04:13 AM


All times are GMT +3. The time now is 10:25 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org