Results 1 to 12 of 12
  1. #1
    eagle26 is offline Member
    Join Date
    Jun 2011
    Posts
    5
    Rep Power
    0

    Default putting the output of different methods inside a method automatically

    i have a method with its variables depending on the outputs of other methods(these methods are in different classes each with inputs from different objects from different classes) , how can i call this main method in the main so that by calling it , the other methods automatically calculates their outputs depending on their inputs
    ex. the main method N=3*x+4/y
    And
    x=3*a+22*b
    a=2*c
    y=44*d+22*a
    d=55*z
    Thanks in advance for any replies and any useful links will be much appreciated

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    how can i call this main method in the main
    Your use of method names is confusing. The method named main() has a special usage. It is the first method called by the java command. The only thing that should be done in that method is to start your application.

    How are the posted arithmetic expressions related to your problem?

    Can you post some sample code that shows what you are trying to do.

    putting the output of different methods inside a method
    variable = aMethod(args); // get output of a method

    Be sure to wrap your code in code tags. Use the # icon.

  3. #3
    eagle26 is offline Member
    Join Date
    Jun 2011
    Posts
    5
    Rep Power
    0

    Default

    this is the method which gives the final output in the program, it's found in class called system

    public void calc_N_Coverage_DL(Base_Station r,Enviroment f, system g)
    {g.N_coverage=Enviroment.area/r.site_area_UL;
    }

    this is the method used to calculate the denominator of the previous method
    public void calc_site_area_UL(Base_Station r, Okumura o,Okumura q)
    {
    some equations
    }

    in those equations there's variables calculated through other methods in different classes , in those other methods there's variables calculated also by other methods and so on

    so i just want to connect all those methods so that when the user presses calculate N(the final output) button, the program automatically sees that it needs "site_area_UL" so it calculates it through its method and the programs moves that way until it calculates all the variables needed to have the final output.

    How can i achieve that ?
    Thank u for your response

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    Your description of what you want to do sounds like the normal way a program is written.
    MethodA calls methodB which calls methodD and methodE and returns a value to its caller MethodA.

    the program automatically sees that it needs "site_area_UL"
    There is nothing automatic there. The programmer must anticipate what is needed to perform the calculations and call the methods required to get the value. The variables being used in the calculations must have good values.

    I guess your pseudo code did not explain what you are trying to do.

  5. #5
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default

    I notice your methods return void. Do you understand how to return a value from a method?
    Get in the habit of using standard Java naming conventions!

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    I think the OP is not hiding variables but using them globally.
    Java Code:
    g.N_coverage=Enviroment.area/r.site_area_UL
    Here the code get variables from several other classes.
    This makes for fragile code that is easily broken.
    Look into using getters and setters. Or with putting the data into the class that uses it in computations.

  7. #7
    eagle26 is offline Member
    Join Date
    Jun 2011
    Posts
    5
    Rep Power
    0

    Default

    i have got a situation regarding calling the methods, in my code i already wrote methods but each method is separate (not calling other methods) in classes , i defined each method with local objects because those methods are used by different objects for ex
    public void calc_average_bit_rate_method1 (Service r,LTE_system f)
    {

    r.average_bit_rate=r.bit_rate_per_RB*f.no_of_RBs;

    }

    ,is that was supposed to be done? now i want to insert in MethodA, the MethodsB and C which are needed by MethodA . but when i do so i have to call MethodB with the objects(defined in the main) not the local objects, so are red ripples below the objects in the MethodsB and C ,what should what i do?

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    i want to insert in MethodA, the MethodsB and C
    Do you mean: in methodA I want to call methodB and methodC
    the objects(defined in the main)
    You should not define any object in the main() method. Except for some very local variables.

    so are red ripples below the objects
    I guess this is your IDE signalling a problem.

    Can you write some simple code showing the problem?
    Last edited by Norm; 06-28-2011 at 12:07 AM. Reason: Ask for code

  9. #9
    eagle26 is offline Member
    Join Date
    Jun 2011
    Posts
    5
    Rep Power
    0

    Default

    this is a method found in class1
    public void calc_N_Coverage_UL(Base_Station r,Enviroment f,LTE_system g)
    {g.N_coverage=Enviroment.area/r.site_area_UL;
    }



    this method found in class 2
    public void calc_site_area_UL(Base_Station r, Okumura o,Okumura q)
    {

    {
    r.site_area_UL=1.949*o.cell_Radius*o.cell_Radius;
    r.site_area_DL=1.949*q.cell_Radius*o.cell_Radius;
    }
    }
    those r the objects i defined in the main
    Enviroment Environment_UL= new Enviroment();
    Enviroment Environment_DL= new Enviroment();
    LTE_system LTE_system_UL= new LTE_system();
    LTE_system LTE_system_DL= new LTE_system();
    UE LTE_UE= new UE();
    Base_Station eNodeB= new Base_Station();


    i used to write the following in the main to call the methods manually now want the methods to call each other but i don't know what's the best way 2 do so, even in the method i tried i has the problms i mentioned at the previous thread

    eNodeB.calc_site_area_UL(eNodeB, Okumura_UL, Okumura_DL);
    LTE_system_UL.calc_N_Coverage_UL(eNodeB, Environment_UL, LTE_system_UL);

    thanks for response.

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    It'd really help in the posted code if you named your methods: methodA and methodB etc as in your earlier post.
    Your long method names are hard to read. Which method is A and which is B etc???

    Also put your code in code tags to preserve formatting.

  11. #11
    eagle26 is offline Member
    Join Date
    Jun 2011
    Posts
    5
    Rep Power
    0

    Default

    in class 1
    public void Method1...

    g.N_coverage=MethodB/MethodC


    in class 2
    public void MethodC{
    ....
    }

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    Ok.
    To call a method that is in a class, you must have a reference to that class.
    Java Code:
    class Class1 { 
      ...
    Class2 cls2 = ???;  // reference to Class2
    ...
    public void method1() {
    ...
    g.N_coverage = methodB()/cls2.methodC();  // access methodC in Class2
    
    } // end method1

Similar Threads

  1. Using variables inside methods?
    By Forty0ztoFreedom in forum New To Java
    Replies: 2
    Last Post: 04-08-2011, 07:36 PM
  2. Replies: 4
    Last Post: 02-13-2011, 12:03 PM
  3. Putting graphics into the run() method.
    By theCardboardBox in forum New To Java
    Replies: 11
    Last Post: 11-17-2010, 06:33 PM
  4. creating objects by methods automatically
    By thedarlington in forum New To Java
    Replies: 13
    Last Post: 02-07-2010, 10:48 PM
  5. Call a Method Automatically
    By rhm54 in forum New To Java
    Replies: 4
    Last Post: 02-07-2008, 08:51 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •