Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Straßenkreuzung
- {
- private Ampel[] ampeln;
- public Straßenkreuzung()
- {
- //Array enthält 12 Ampeln
- ampeln = new Ampel[12];
- //4 Ampeln für die Straßen erstellen
- for(int i = 0; i < 4; i++)
- {
- ampeln[i] = new Ampel(1); //Straßenampel
- //weitere 8 Ampeln für die Fußgänger
- for(int x = 0; x < 2; x++)
- {
- ampeln[i*x+4] = new Ampel(2); //Fußgängerampel
- }
- }
- }
- public void wechsel()
- {
- for(int i = 0; i < ampeln.length; i++) // Durchläuft alle 12 Ampeln
- {
- ampeln[i].schalten(); //Schaltet jede Ampel einmal durch
- }
- }
- public void statusanzeige()
- {
- for(int i = 0; i < ampeln.length; i++)// Durchläuft alle 12 Ampeln
- {
- System.out.println("Ampel " + i + ": Zustand = " + ampeln[i].zustand); //Gibt den Status der Ampel in der Konsole aus
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment