Results 1 to 9 of 9
- 02-26-2009, 09:04 AM #1
How to Cal methods within a method in the same class
Hi pple,
I am writing a program that does calcution of certain functions.The functions are related and somehow i have to interlink the methods.
So my question is, How can i call a method within another method in the same class
Your response will be higly appreciated
thnx
- 02-26-2009, 10:43 AM #2
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
you can call by this.methodName(yyy,zzz)
or just methodName (yyy, zz)
- 02-26-2009, 01:22 PM #3
Am stil confused. Let me give u an example so tht u can know what am talking about
Now my question is ,how do i access the values from the other method(calcEquillibrium)?.Java Code:public class XenonConcUI extends javax.swing.JFrame { public XenonConcUI() { initComponents(); } public void calEqulibrium(double Phi_t, double IodConc_t_1, double XenConc_t_1) { //here i calculate Phi_t, IodConc_t_1 and XenConc_t_1 } public double result(double xenPoison) { //In this method, i calculate xenPoist but to calculate it i need the values of Phi_t, IodConc_t_1 and XenConc_t_1 from the method above
I just hope my explanation is clear.
thanx
- 02-26-2009, 02:03 PM #4
You're methods don't seen t be static, so probably you have to instantiate the class and then call the method:
Now... calEquilibreium doesn't return any values ... you might want to change that for your purposes.Java Code:XenonConcUI xc = new XenonConcUI(); xc.calEqulibrium(x, y z);
Luck,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 02-27-2009, 02:27 AM #5
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
would you mind to add some global variables
- 02-27-2009, 04:13 AM #6
You can call a method in the same class w/ this example
public class foo {
public int method1(int number) {
int num1 = this.method2();
int num2 = this.method3();
return 0;
}
private int method2() {
return 0;
}
public int method3() {
return 0;
}
}
or if your class is a main
public class Runner {
public static void main(String[] args) {
method1();
method2();
}
private static void method1() {
}
public static void method2() {
}
}
hope this helps
- 02-27-2009, 08:36 AM #7
My dear friends,thanks for your response but am still in darkness. I just want to get this concept once and for all and i tried to creat a practice program and its still giving me problems. I have added the code below and i kindly request tht u edit my code to the way it should be without bugs. this way i will get the concept.
Just correct where am going wrongJava Code:package MonthlyPayments; /** * * @author MUNYA00M */ public class Payments { static double rate; static double loanAmt; static double futureValue; static double numPeriods; public double input(double rate, double loanAmt,double futureValue,double numPeriods){ rate = 10; loanAmt = 2000; futureValue = 2500; numPeriods = 24; } public double computePayment(double loanAmt, double rate, double futureValue, int numPeriods) { double interest = rate / 100.0; double partial1 = Math.pow((1 + interest), -numPeriods); double denominator = (1 - partial1) / interest; double answer = (-loanAmt / denominator) - ((futureValue * partial1) / denominator); return answer; } /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Payments py = new Payments(); double rate =this.input(); double loanAmt =this.input(loanAmt); py.input(rate,loanAmt,futureValue,numPeriods); py.computePayment(answer); System.out.println(answer); } }
thanks a bunchLast edited by Manfizy; 02-27-2009 at 08:47 AM.
- 02-27-2009, 08:56 AM #8
:D
:) try this
Java Code:public class Payments { static double rate; static double loanAmt; static double futureValue; static double numPeriods; /** * @param args * the command line arguments */ public static void main(String[] args) { // TODO code application logic here rate = 10; loanAmt = 2000; futureValue = 2500; numPeriods = 24; double answer = computePayment(loanAmt, rate, futureValue, numPeriods); System.out.println(answer); } private static double computePayment(double loanAmt, double rate, double futureValue, double numPeriods) { double interest = rate / 100.0; double partial1 = Math.pow((1 + interest), -numPeriods); double denominator = (1 - partial1) / interest; double answer = (-loanAmt / denominator) - ((futureValue * partial1) / denominator); return answer; } }
- 03-03-2009, 08:28 AM #9
Similar Threads
-
Calling a method in a different class from within a method problem
By CirKuT in forum New To JavaReplies: 29Last Post: 09-25-2008, 07:55 PM -
Declare methods in a class
By Adiel224 in forum New To JavaReplies: 5Last Post: 09-19-2008, 10:38 AM -
Calling a method on original class from created class
By kpedersen in forum Advanced JavaReplies: 4Last Post: 08-20-2008, 12:25 AM -
Class Reflection: Showing methods
By Java Tip in forum java.langReplies: 0Last Post: 04-23-2008, 08:11 PM -
Getting methods of a Class - Reflection
By Java Tip in forum Java TipReplies: 0Last Post: 11-15-2007, 03:18 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks