Created
September 26, 2021 21:34
-
-
Save lucaspolo/d85705413d2771b23678805d06466336 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, 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