Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. package com.company;
  2.  
  3. public class semaforo {
  4.  
  5. public enum typeStati{sSpento, sAcceso, sCambia1, sCambia2, sAllarme} //cambia1 = giallo cambia2 = rosso
  6. private typeStati stato;
  7.  
  8. public semaforo(){
  9. stato = typeStati.sSpento;
  10. }
  11.  
  12. public String getStato(){
  13. if (stato == typeStati.sSpento){
  14. return "Spento";
  15. }
  16. if (stato == typeStati.sAcceso){
  17. return "Verde";
  18. }
  19. if (stato == typeStati.sCambia1){
  20. return "Giallo";
  21. }
  22. if (stato == typeStati.sCambia2){
  23. return "Rosso";
  24. }
  25. if (stato == typeStati.sAllarme){
  26. return "Giallo lampeggiante";
  27. }
  28. return "";
  29. }
  30.  
  31. public void acceso(){
  32. if (stato == typeStati.sSpento){
  33. stato = typeStati.sAcceso;
  34. }else
  35. if (stato == typeStati.sCambia2){
  36. stato = typeStati.sAcceso;
  37. }else
  38. if (stato == typeStati.sAllarme){
  39. stato = typeStati.sAcceso;
  40. }
  41. }
  42.  
  43. public void spento(){
  44. if (stato == typeStati.sAcceso){
  45. stato = typeStati.sSpento;
  46. }else
  47. if (stato == typeStati.sAllarme){
  48. stato = typeStati.sSpento;
  49. }
  50. }
  51.  
  52. public void cambia(){
  53. if (stato == typeStati.sAcceso){
  54. stato = typeStati.sCambia1;
  55. }else
  56. if (stato == typeStati.sCambia1){
  57. stato = typeStati.sCambia2;
  58. }else
  59. if (stato == typeStati.sCambia2){
  60. stato = typeStati.sAcceso;
  61. }
  62. }
  63.  
  64. public void allarme(){
  65. stato = typeStati.sAllarme;
  66. }
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement