Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-21-2012, 05:52 AM   PM User | #1
Taro
Regular Coder

 
Taro's Avatar
 
Join Date: Oct 2011
Location: Geraldton, Ontario
Posts: 155
Thanks: 1
Thanked 1 Time in 1 Post
Taro is an unknown quantity at this point
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"
__________________
Element ID

Webs Support Helper

Your friendly neighborhood Taroman.

Last edited by Taro; 10-21-2012 at 05:56 AM.. Reason: C++?
Taro is offline   Reply With Quote
Old 10-21-2012, 05:57 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 10-21-2012, 09:13 PM   PM User | #3
Taro
Regular Coder

 
Taro's Avatar
 
Join Date: Oct 2011
Location: Geraldton, Ontario
Posts: 155
Thanks: 1
Thanked 1 Time in 1 Post
Taro is an unknown quantity at this point
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.
Taro is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:13 PM.


Advertisement
Log in to turn off these ads.