aveenger17

generatrafico.java

Feb 15th, 2013
590
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3. //En esta clase el trafico de las calles se forma de manera aleatoria
  4.  
  5. public class generatrafico{
  6.     public int A,B,C,D,n,trafico=0;  
  7.    
  8.     generatrafico(){
  9.         Random tr = new Random();
  10.         for(n=0;n<4;n++){
  11.             if(n==0){
  12.                 trafico = 1 + tr.nextInt(6); //Genera trafico de 1 a 7 vehiculos
  13.                 A = trafico;
  14.                 }
  15.             if(n==1){
  16.                 trafico = 1 + tr.nextInt(6);
  17.                 B = trafico;
  18.                 }
  19.             if(n==2){
  20.                 trafico = 1 + tr.nextInt(6);
  21.                 C = trafico;
  22.                 }
  23.             if(n==3){
  24.                 trafico = 1 + tr.nextInt(6);
  25.                 D = trafico;
  26.                 }  
  27.         }
  28.  
  29.     }
  30.    
  31.     public int getA(){
  32.         return A;
  33.     }
  34.    
  35.     public int getB(){
  36.         return B;
  37.     }
  38.    
  39.     public int getC(){
  40.         return C;
  41.     }
  42.    
  43.     public int getD(){
  44.         return D;
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment