Created
August 27, 2024 10:53
-
-
Save SpinnerZ/f13350d25f508115fdbdbe03ddd160c9 to your computer and use it in GitHub Desktop.
Estruturas condicionais em Java - if
This file contains hidden or 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 org.example; | |
| import java.util.Scanner; | |
| public class EstruturasDeDecisao { | |
| public static void main(String[] args) { | |
| final short MANDATORY_VOTING_AGE = 18; | |
| final short OPTIONAL_VOTING_AGE = 16; | |
| final String MANDATORY_VOTING_MESSAGE = "Você é maior de idade, portanto é OBRIGADO a votar."; | |
| final String OPTIONAL_VOTING_MESSAGE = "Pela sua idade, o voto é opcional."; | |
| final String FORBIDDEN_VOTING_MESSAGE = "Você é menor de idade, portanto é PROIBIDO de votar"; | |
| Scanner scanner = new Scanner(System.in); | |
| short userAge; | |
| System.out.println("\nBem vindo ao programa eleitoral da Pretas Tech!\n"); | |
| System.out.print("Por favor insira a idade do eleitor: "); | |
| userAge = scanner.nextShort(); | |
| /* // if (inglês) == se (português) | |
| if (userAge >= MANDATORY_VOTING_AGE) { | |
| System.out.println("Você já pode votar!"); | |
| // else == se não | |
| } else { | |
| System.out.println(""); | |
| }*/ | |
| /* if (userAge >= OPTIONAL_VOTING_AGE) { | |
| if (userAge >= MANDATORY_VOTING_AGE) | |
| System.out.println("Você está na faixa da idade eleitoral OBRIGATÓRIA."); | |
| else System.out.println("Você está na faixa da idade eleitoral OPCIONAL."); | |
| } | |
| if (userAge < OPTIONAL_VOTING_AGE) | |
| System.out.println("Você é muito jovem, e ainda NÃO PODE VOTAR");*/ | |
| /*if (userAge >= MANDATORY_VOTING_AGE) System.out.println(MANDATORY_VOTING_MESSAGE); | |
| else if (userAge >= OPTIONAL_VOTING_AGE) System.out.println(OPTIONAL_VOTING_MESSAGE); | |
| else System.out.println(FORBIDDEN_VOTING_MESSAGE);*/ | |
| // if (userAge >= MANDATORY_VOTING_AGE) { | |
| // System.out.println(MANDATORY_VOTING_MESSAGE); | |
| // } | |
| // else if (userAge >= OPTIONAL_VOTING_AGE) { | |
| // System.out.println(OPTIONAL_VOTING_MESSAGE); | |
| // } | |
| // else { | |
| // System.out.println(FORBIDDEN_VOTING_MESSAGE); | |
| // } | |
| if ((userAge >= MANDATORY_VOTING_AGE) || (userAge >= OPTIONAL_VOTING_AGE)) { | |
| System.out.println(MANDATORY_VOTING_MESSAGE); | |
| System.out.println(OPTIONAL_VOTING_MESSAGE); | |
| } | |
| else { | |
| System.out.println(FORBIDDEN_VOTING_MESSAGE); | |
| } | |
| // IMPLEMENTE A FUNCIONALIDADE DE VOTO OPCIONAL PARA IDOSOS | |
| System.out.println("Pesquise bem os candidados existentes e vote consciente!"); | |
| scanner.close(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment