Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder Taro's Avatar
    Join Date
    Oct 2011
    Location
    Geraldton, Ontario
    Posts
    155
    Thanks
    1
    Thanked 1 Time in 1 Post

    Java Commands performed based on integer value

    Hello,

    I am trying to figure out how to set integers for a robot to perform different tasks. For example, if x=1 it will perform task one; if x=2 it will perform task two. So to put this all together for the function that I want it to perform, it is supposed to do task one first. When task one is done, the computer does a x++ to increase the value by one so it can go to perform tasks 2. I tried it my self but have come to no avail. The following is some of my code, which includes a main method file and a resource class file; the imported files are irrelevant.

    Resource Class File snippet:
    Code:
    public void task1(int numSpa, int numBeep)
          {
    			move();
             jumpRight();
             sprint(numSpa);
             pick(numBeep);
             turnAround();
             sprint(numSpa);
             jumpLeft();
             move();
             put(numBeep);
             turnAround();
             move();		
          }
    EDIT:
    I tried incorporating the for statement, such as for(int r=0; r<3; r++/*C++?*/),and even tried to do this:
    x=1="task1"
    Last edited by Taro; 10-21-2012 at 05:56 AM. Reason: C++?
    Element ID

    Webs Support Helper

    Your friendly neighborhood Taroman.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    I don't understand what you are doing here.
    Does task1 always call task2? If so, simply call task2 once task1 is complete. If that's not what you want, pass an object of type Integer into the method which can be incremented, and then let the main program continue with its loop. You could also return a result from the task method and let the main handle if it should increment.
    A complete alternative would be to use threading and a synchronized List<Method>. Then while the list has methods in it, iterate and call them in order, and shift them off of the list. Then the main program just needs to keep adding to the list and the thread will come around and execute them. Most useful if these are background tasks, otherwise you'll need to force a thread to run.

  • #3
    Regular Coder Taro's Avatar
    Join Date
    Oct 2011
    Location
    Geraldton, Ontario
    Posts
    155
    Thanks
    1
    Thanked 1 Time in 1 Post
    Yes, I'll just have to call the resource class method and define the integer without a static type; that way, there won't be any confusion as opposed to using the arguments for the main class.
    Element ID

    Webs Support Helper

    Your friendly neighborhood Taroman.


  •  

    Posting Permissions

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