Skip to content

Instantly share code, notes, and snippets.

@lucaspolo
Created September 26, 2021 21:48
Show Gist options
  • Save lucaspolo/75d58c614f4d86ea3d4575fd9d14374b to your computer and use it in GitHub Desktop.
Save lucaspolo/75d58c614f4d86ea3d4575fd9d14374b to your computer and use it in GitHub Desktop.
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