Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Ampel {
- static int gruen = 1;
- static int gelb = 2;
- static int rot = 3;
- static int rotGelb = 4;
- static int farbe;
- static int wartezeit = 5000;
- public static void main(String[] args){
- machAmpeldinge();
- }
- public static void wechsleGruen(){
- try{
- Thread.sleep(5000);
- }catch(InterruptedException ex) {
- Thread.currentThread().interrupt();
- }
- farbe = rotGelb;
- if(farbe == 4){
- System.out.println("rotGelb");
- }
- try{
- Thread.sleep(5000);
- }catch(InterruptedException ex) {
- Thread.currentThread().interrupt();
- }
- farbe = gruen;
- if(farbe == 1){
- System.out.println("gruen");
- }
- }
- public static void wechsleGelb(){
- try{
- Thread.sleep(5000);
- }catch(InterruptedException ex) {
- Thread.currentThread().interrupt();
- }
- farbe = gelb;
- if(farbe == 2){
- System.out.println("gelb");
- }
- }
- public static void wechsleRot(){
- try{
- Thread.sleep(5000);
- }catch(InterruptedException ex) {
- Thread.currentThread().interrupt();
- }
- farbe = rot;
- if(farbe == 3){
- System.out.println("rot");
- }
- }
- public static void machAmpeldinge(){
- while(true){
- wechsleGruen();
- wechsleGelb();
- wechsleRot();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement