Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Write a description of class Straßenkreuzung here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class Straßenkreuzung
- {
- private Ampel[] ampeln = new Ampel[12];
- private boolean[] strasse1 = new boolean[]{true,false,true,false,true,true,false,false,true,true,false,false};
- /**
- * Simuliert eine Kreuzung zweier straßen mit Ampeln, und Fußgängerampeln
- *
- */
- public Straßenkreuzung() {
- for(int a = 0; a < 4; a++) {
- ampeln[a] = new Ampel(1);
- }
- for (int b = 4; b < 12; b++) {
- ampeln[b] = new Ampel(2);
- }
- for (int i = 0; i < 12; i++) {
- if(ampeln[i].getTyp() == 1 && strasse1[i]) {
- ampeln[i].schalten();
- ampeln[i].schalten();
- } else if (ampeln[i].getTyp() == 2 && strasse1[i]) {
- ampeln[i].schalten();
- }
- }
- System.out.println("Straßenkreuzung wurde erzeugt. Str. 1 hat jetzt grünes Licht!");
- statusanzeige();
- }
- public void wechsel() {
- for (int i = 0; i < 12; i++) {
- if(ampeln[i].getTyp() == 1) {
- ampeln[i].schalten();
- ampeln[i].schalten();
- } else if (ampeln[i].getTyp() == 2) {
- ampeln[i].schalten();
- }
- }
- statusanzeige();
- }
- public void statusanzeige() {
- for (int i = 0; i < 12; i++) {
- System.out.println("Ampel " + (i+1) + ": Zustand = " + ampeln[i].getZustand());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement