Created
September 26, 2021 21:48
-
-
Save lucaspolo/75d58c614f4d86ea3d4575fd9d14374b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.company; | |
public class Main { | |
public enum Veiculos { | |
BICICLETA(0), MOTO(1), CARRO(2), ONIBUS(4), CAMINHAO(3); | |
private final float tarifa; | |
Veiculos(float tarifa) { | |
this.tarifa = tarifa; | |
} | |
} | |
public static void main(String[] args) { | |
var veiculo = Veiculos.CAMINHAO; | |
float valorPedagio = switch (veiculo) { | |
case MOTO, CARRO -> veiculo.tarifa; | |
case ONIBUS, CAMINHAO -> { | |
var adicional = 5; | |
yield veiculo.tarifa + adicional; | |
} | |
default -> 0; | |
}; | |
System.out.println("Você deverá pagar um pedágio de " + valorPedagio); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment