Skip to content

Instantly share code, notes, and snippets.

@lucaspolo
Created September 26, 2021 21:34
Show Gist options
  • Save lucaspolo/d85705413d2771b23678805d06466336 to your computer and use it in GitHub Desktop.
Save lucaspolo/d85705413d2771b23678805d06466336 to your computer and use it in GitHub Desktop.
package com.company;
public class Main {
public enum Veiculos {
BICICLETA, MOTO, CARRO, ONIBUS, CAMINHAO
}
public static void main(String[] args) {
var veiculo = Veiculos.CAMINHAO;
float valorPedagio = switch (veiculo) {
case MOTO -> valorPedagio = 1;
case CARRO -> valorPedagio = 2;
case CAMINHAO -> valorPedagio = 3;
case ONIBUS -> valorPedagio = 4;
default -> 0; // Como não cobrimos todos os casos eu preciso definir um default
}; // Por ser uma expressão precisa terminar com ;
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