Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- public class semaforo {
- public enum typeStati{sSpento, sAcceso, sCambia1, sCambia2, sAllarme} //cambia1 = giallo cambia2 = rosso
- private typeStati stato;
- public semaforo(){
- stato = typeStati.sSpento;
- }
- public String getStato(){
- if (stato == typeStati.sSpento){
- return "Spento";
- }
- if (stato == typeStati.sAcceso){
- return "Verde";
- }
- if (stato == typeStati.sCambia1){
- return "Giallo";
- }
- if (stato == typeStati.sCambia2){
- return "Rosso";
- }
- if (stato == typeStati.sAllarme){
- return "Giallo lampeggiante";
- }
- return "";
- }
- public void acceso(){
- if (stato == typeStati.sSpento){
- stato = typeStati.sAcceso;
- }else
- if (stato == typeStati.sCambia2){
- stato = typeStati.sAcceso;
- }else
- if (stato == typeStati.sAllarme){
- stato = typeStati.sAcceso;
- }
- }
- public void spento(){
- if (stato == typeStati.sAcceso){
- stato = typeStati.sSpento;
- }else
- if (stato == typeStati.sAllarme){
- stato = typeStati.sSpento;
- }
- }
- public void cambia(){
- if (stato == typeStati.sAcceso){
- stato = typeStati.sCambia1;
- }else
- if (stato == typeStati.sCambia1){
- stato = typeStati.sCambia2;
- }else
- if (stato == typeStati.sCambia2){
- stato = typeStati.sAcceso;
- }
- }
- public void allarme(){
- stato = typeStati.sAllarme;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement