Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. public class Ampel {
  2. static int gruen = 1;
  3. static int gelb = 2;
  4. static int rot = 3;
  5. static int rotGelb = 4;
  6. static int farbe;
  7. static int wartezeit = 5000;
  8.  
  9. public static void main(String[] args){
  10. machAmpeldinge();
  11. }
  12.  
  13. public static void wechsleGruen(){
  14. try{
  15. Thread.sleep(5000);
  16. }catch(InterruptedException ex) {
  17. Thread.currentThread().interrupt();
  18. }
  19. farbe = rotGelb;
  20. if(farbe == 4){
  21. System.out.println("rotGelb");
  22. }
  23. try{
  24. Thread.sleep(5000);
  25. }catch(InterruptedException ex) {
  26. Thread.currentThread().interrupt();
  27. }
  28. farbe = gruen;
  29. if(farbe == 1){
  30. System.out.println("gruen");
  31. }
  32.  
  33. }
  34. public static void wechsleGelb(){
  35. try{
  36. Thread.sleep(5000);
  37. }catch(InterruptedException ex) {
  38. Thread.currentThread().interrupt();
  39. }
  40. farbe = gelb;
  41. if(farbe == 2){
  42. System.out.println("gelb");
  43. }
  44. }
  45. public static void wechsleRot(){
  46. try{
  47. Thread.sleep(5000);
  48. }catch(InterruptedException ex) {
  49. Thread.currentThread().interrupt();
  50. }
  51. farbe = rot;
  52. if(farbe == 3){
  53. System.out.println("rot");
  54. }
  55. }
  56. public static void machAmpeldinge(){
  57. while(true){
  58. wechsleGruen();
  59. wechsleGelb();
  60. wechsleRot();
  61. }
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement