java - Four Way Intersection Simulation -


i'm trying write program displays light sequences @ 4 way intersection.

the direcitons are:

at given time traffic can move in 1 direction. traffic lights have 3 colors red, yellow , green. based on event. lights change color in synchronized way allow safe driving. define class called “trafficlight” has 2 methods. 1 called “change” , called “getcolor”. in separate class “assignment5”, main entry point, want create 4 trafficlight instances 2 north/south traffic , 2 east/west traffic. using 2 methods objects provide want show have correctly simulated 4 way traffic light.

i need implement these program.

so far have:

 public class trafficlight {  /**  * @param args  */ public trafficlight(int c){     this.c = c;  }//end constructor   public int getc(){     return c; }  java.lang.string getcolor;     string n = "gyr";     string s = "gyr";     string e = "gyr";     string w = "gyr";   public void change(){     int c = 1;       while (c <= 4){          if (c == 1){             n.charat(2);             s.charat(2);             e.charat(0);             w.charat(0);             c++;          }          else if (c == 2){             n.charat(2);             s.charat(2);             e.charat(1);             w.charat(1);             c++;          }          else if (c == 3){             n.charat(0);             s.charat(0);             e.charat(2);             w.charat(2);             c++;          }          else if (c == 4){             n.charat(1);             s.charat(1);             e.charat(2);             w.charat(2);             c++;          }           while (c >= 5)              if (c-4 == 1){                 n.charat(2);                 s.charat(2);                 e.charat(0);                 w.charat(0);                 c++;              }              else if (c-4 == 2){                 n.charat(2);                 s.charat(2);                 e.charat(1);                 w.charat(1);                 c++;              }              else if (c-4 == 3){                 n.charat(0);                 s.charat(0);                 e.charat(2);                 w.charat(2);                 c++;              }              else if (c-4 == 4){                 n.charat(1);                 s.charat(1);                 e.charat(2);                 w.charat(2);                 c++;              }          system.out.println(n);         system.out.println(s);         system.out.println(e);         system.out.println(w);       }//end inner while loop  }//end 'change'   private int c;    }//end class 

the sample output should like:

traffic light event 1:  north light: red south light: red east light: green west light: green  traffic light event 2:  north light: red south light: red east light: yellow west light: yellow  traffic light event 3:  north light: green south light: green east light: red west light: red  traffic light event 4:  north light: yellow south light: yellow east light: red west light: red  traffic light event 5:  north light: red south light: red east light: green west light: green  traffic light event 6:  north light: red south light: red east light: yellow west light: yellow  traffic light event 7:  north light: green south light: green east light: red west light: red  traffic light event 8:  north light: yellow south light: yellow east light: red west light: red  traffic light event 9:  north light: red south light: red east light: green west light: green  traffic light event 10:  north light: red south light: red east light: yellow west light: yellow  traffic light event 11:  north light: green south light: green east light: red west light: red  traffic light event 12:  north light: yellow south light: yellow east light: red west light: red 

how go implementing this? thoughts?


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -