Guest User

Untitled

a guest
Jan 23rd, 2017
3
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1. class Straßenkreuzung
  2. {
  3.  
  4.     private Ampel[] ampeln;
  5.     public Straßenkreuzung()
  6.     {
  7.         //Array enthält 12 Ampeln
  8.         ampeln = new Ampel[12];
  9.         //4 Ampeln für die Straßen erstellen
  10.         for(int i = 0; i < 4; i++)
  11.             {
  12.                 ampeln[i] = new Ampel(1); //Straßenampel
  13.                 //weitere 8 Ampeln für die Fußgänger
  14.                 for(int x = 0; x < 2; x++)
  15.                 {
  16.                     ampeln[i*x+4] = new Ampel(2); //Fußgängerampel
  17.                 }
  18.             }
  19.        
  20.     }
  21.  
  22.     public void wechsel()
  23.     {
  24.         for(int i = 0; i < ampeln.length; i++) // Durchläuft alle 12 Ampeln
  25.         {
  26.             ampeln[i].schalten(); //Schaltet jede Ampel einmal durch
  27.         }
  28.     }
  29.  
  30.     public void statusanzeige()
  31.     {
  32.         for(int i = 0; i < ampeln.length; i++)// Durchläuft alle 12 Ampeln
  33.         {
  34.             System.out.println("Ampel " + i + ": Zustand = " + ampeln[i].zustand); //Gibt den Status der Ampel in der Konsole aus
  35.         }
  36.     }
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment