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-15-2007, 02:01 AM
Member
 
Join Date: Nov 2007
Location: boston
Posts: 10
lowpro is on a distinguished road
need help calling methods
//this code should calculate future investment but is not
//it should print years from 1 to 30 and future value
// i'm new in java please help me out.thnks adv

import java.util.Scanner;


public class C5E7{
public static void main(String [] args){

Scanner input = new Scanner(System.in);
//double k = futureInvestementValue( a, b, c, d);


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

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

System.out.println("THE AMOUNT INVESTED IS:" + investmentAmount);
System.out.println("THE ANNUAL INTEREST RATE IS:" + rate);
for( int i = 1; i <= 30; ++years)

System.out.println(years + "\t\t" + futureInvestmentValue);
System.out.println("YEARS\t\tFUTURE VALUE");


{


public static double futureInvestmentValue(double investmentAmount, double monthlyInterestRate int years)
{
// double monthlyInterestRate;
result = 0;
// monthlyInterestRate = rate /12;
futureInvestmentValue = investmentAmount * (1+ monthlyInterest)numberOfYears * 12;
years = years + 1;
double result = futureInvestmentValue;
return result;

}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-15-2007, 02:49 AM
JT4NK3D's Avatar
Member
 
Join Date: Nov 2007
Posts: 50
JT4NK3D is on a distinguished road
Quote:
//this code should calculate future investment but is not
//it should print years from 1 to 30 and future value
// i'm new in java please help me out.thnks adv

import java.util.Scanner;


public class C5E7{
public static void main(String [] args){

Scanner input = new Scanner(System.in);
//double k = futureInvestementValue( a, b, c, d);


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

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

System.out.println("THE AMOUNT INVESTED IS:" + investmentAmount);
System.out.println("THE ANNUAL INTEREST RATE IS:" + rate);
for( int i = 1; i <= 30; ++years)

System.out.println(years + "\t\t" + futureInvestmentValue);
System.out.println("YEARS\t\tFUTURE VALUE");


{


public static double futureInvestmentValue(double investmentAmount, double monthlyInterestRate int years)
{
// double monthlyInterestRate;
result = 0;
// monthlyInterestRate = rate /12;
futureInvestmentValue = investmentAmount * (1+ monthlyInterest)numberOfYears * 12;
years = years + 1;
double result = futureInvestmentValue;
return result;

}
One easy to spot problem is with your parameters -

Quote:
public static double futureInvestmentValue(double investmentAmount, double monthlyInterestRate int years)
{
// double monthlyInterestRate;
result = 0;
// monthlyInterestRate = rate /12;
futureInvestmentValue = investmentAmount * (1+ monthlyInterest)numberOfYears * 12;
years = years + 1;
double result = futureInvestmentValue;
return result;

}
change the parameters inside the parintheses,
Quote:
public static double futureInvestmentValue(double investmentAmount, double monthlyInterestRate, int years)
you forgot the comma. There must be a comma between each parameter, next error, :
Quote:
//double k = futureInvestementValue( a, b, c, d);
get rid of those // comment tags, i got no clue why they're there, and your method has 3 parameters while you declare 4 arguments. I dont see where the variables a b c and d came from or why its called k. if this was supposed to be a comment, where did you try calling the method then? and theres another error, you tried acessing local variables from your method in main. that will not work, they are only accessible from their method. instead return the value of the variable you want to access in your method. to get it use syntax in main:

yourVariable = futureInvestmentValue(argument 1, argument 2, argument 3);
(write code with that syntax in main, then you can access the value it returns). right now, with your code as it is you can only acess the methods return value, result in any other method besides futureInvestmentValue

you used a static method. a better approach is try using a non-static first, which is after all the point of OOP. to call non statics use syntax:

yourClassName yourObjectName = new yourClassName(); /* use arguments inside parentheses if you have parameters in your constuctor. (if you have one. if you dont, you should still declare an empty constructor.*/

variableType yourVariableName = yourObjectName.futureInvestmentValue(arguments);
you can then use it in your program.

example:

public class accessDemo {

public static void main(String[] args) {

acessDemo acdemo = new acessDemo();
double acessmethodreturn = acDemo.futureInvestmentValue(arguments);

// then you can use it in your program.


acDemo can be named anything you want. if your constructor has parameters write the arguments in new accessDemo(write the arguments here);

write whatever the arguments need to be for calling the method using the newly created object. also the name of the variable and type that gets the calls the method can be whatever is required/you want

Last edited by JT4NK3D : 11-15-2007 at 02:51 AM.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-15-2007, 11:53 AM
Member
 
Join Date: Nov 2007
Location: boston
Posts: 10
lowpro is on a distinguished road
JT4NK3D thks very much.u really walk me thru. i couldn't understand how it shoulb be done until now. thnks again
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
method calling? frejon26 New To Java 4 01-25-2008 05:38 AM
Constructor calling ravian New To Java 2 12-22-2007 08:53 PM
Calling Java methods form Python mew Advanced Java 1 12-21-2007 04:30 PM
Calling Methods bluegreen7hi New To Java 3 12-17-2007 08:22 AM
Problems with readLine() and calling methods peachyco New To Java 2 11-24-2007 09:44 AM


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


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