5 Replies - 285 Views - Last Post: 14 May 2011 - 03:05 PM Rate Topic: -----

#1 sarah waleed  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 124
  • Joined: 12-January 11

please an idea to switch from state to other

Posted 14 May 2011 - 02:19 PM

hello everybody,
that is the idea that i want to accomplish

Quote

In alert state:
spoof = Inspect();//i do it
t = Average(spoof );
if ( spoof )
if ( t > T1 )
Switch Action();// i have problem in how to do it

In action state:
spoof = Inspect();
t = Average(spoof );
if ( spoof )
"say bad"
else
"say ok";
if ( t < T2 )
Switch Alert();//problem with it too
where T1>T2



a user try to guss and inter,so he try to inter many times, some of them is true, and some is false, and there is no end for that.
i want that when the user inter a value it will checked with Inspect();(i do it), then if it ok or not ok but his wrong avrg is not exceed the T1( no. of try) the state is alert,and still in it untill he reach the T1,then the program switch him to the action state (that say u r bad) and still in it untill the avrg of his falsify is moderate(reach T2)
please i want an idea of how to switch from state to other and still in it, by what statement i do it?
the main program that i can try to write is like this

int T1=3;
do{
System.out.println("u r now in the alert state\n   ok");
spoof=insp(kb);
if(spoof)
spoof++;
avrspoof=spoof/total;
t=avrspoof;
} while(t<T1)
if(spoof && t>T1)
System.out.println("u  now inter the action state\n   u r bad");



please any idea for that,i don't want a complete program just some help
thank u in advance
regards

Is This A Good Question/Topic? 0
  • +

Replies To: please an idea to switch from state to other

#2 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1817
  • View blog
  • Posts: 4,625
  • Joined: 14-March 10

Re: please an idea to switch from state to other

Posted 14 May 2011 - 02:34 PM

i dont get what spoof represent and what insp() does and where you get kb.
You need to move between states and still remain in the loop until when? then you may have something like this:
do{
  if(t<T1){
   //code for alter state
  }
  else if (t>T1){
   //code for action state
  }
}while(condition to Close)


I think will do the trick! If not give us more explanation on what you need to do
Was This Post Helpful? 1
  • +
  • -

#3 japanir  Icon User is offline

  • jaVanir
  • member icon

Reputation: 1010
  • View blog
  • Posts: 3,025
  • Joined: 20-August 09

Re: please an idea to switch from state to other

Posted 14 May 2011 - 02:47 PM

Are you familiar with OOP and Polymorpysm? if so, create an interface\abstract class called State.
extend the State class, something like:
public interface State {
  void inState();
}
public class PauseState implements State {
  public void inState(){
   System.out.println("Paused");
  }
}

public class ExitState implements State {
  public void inState(){
   System.out.println("Exit");
  }
}
...

You can then swith between the states with a state manager class (can be singleton as well) like:

public class StateManager(){
  public State getState(int code){
    switch(code){
       case 1: return new PauseState();
       break;
       case 2: return new ExitState();
       break;
       ..
    }
  }
}

in the main code, you can have something as simple as:

public class DriverClass {
   public static void main(String[] args){
     State state;
     StateManager manager = new StateManager();
     //get a value (from user into stateCode)
     int stateCode = ...
     state = manager.getState(stateCode);
     //call the inState method of State
     state.inState();
  }
}

Was This Post Helpful? 1
  • +
  • -

#4 sarah waleed  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 124
  • Joined: 12-January 11

Re: please an idea to switch from state to other

Posted 14 May 2011 - 02:52 PM

that's great
i am not familer with them but i will try with it if i can to continue
so thank u very much
Was This Post Helpful? 0
  • +
  • -

#5 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1817
  • View blog
  • Posts: 4,625
  • Joined: 14-March 10

Re: please an idea to switch from state to other

Posted 14 May 2011 - 03:03 PM

You can start them from:
Inheritance tutorial
Polymorphism tutorial
inheritance and polymorphism tutorial
Was This Post Helpful? 1
  • +
  • -

#6 sarah waleed  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 124
  • Joined: 12-January 11

Re: please an idea to switch from state to other

Posted 14 May 2011 - 03:05 PM

thanks for all that :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1