Created
November 28, 2021 15:34
-
-
Save julioprotzek/24c85946e8028ab9640f73c96270f2b0 to your computer and use it in GitHub Desktop.
Nota 9.0
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
import javax.swing.*; | |
public class RecomendacaoDeFilmes { | |
public static void main(String[] entrada) { | |
char opcao; | |
String msg = ""; | |
String[] todosOsGeneros = { | |
"Ação", | |
"Terror", | |
"Ficção Científica" | |
}; | |
String[][] todosOsFilmes = { | |
{ | |
"Matrix", | |
"Akira", | |
"O Fantasma do Futuro", | |
"Exterminador do Futuro 2" | |
}, | |
{ | |
"Alien: O Oitavo Passageiro", | |
"Os Outros", | |
"Invocação do Mal", | |
"O Iluminado" | |
}, | |
{ | |
"Blade Runner", | |
"A Chegada", | |
"Interstellar", | |
"Ex Machina" | |
} | |
}; | |
String[] filmesDaPixar = { | |
"Monstros S.A.", | |
"Wall-E", | |
"Os Incríveis", | |
"Brave" | |
}; | |
opcao = JOptionPane.showInputDialog( | |
"Escolha um gênero para receber recomendações:\n" + | |
"\t\t1 - Ação digite\n" + | |
"\t\t2 - Terror digite\n" + | |
"\t\t3 - Ficção Científica\n" + | |
"\t\t0 - Todos\n" | |
).charAt(0); | |
switch (opcao) { | |
case '1': { | |
msg += listarFilmesDoGenero(todosOsGeneros[0], todosOsFilmes[0]); | |
break; | |
} | |
case '2': { | |
if (temIdadeParaAssistirFilmesDeTerror()) { | |
msg += listarFilmesDoGenero(todosOsGeneros[0], todosOsFilmes[0]); | |
} else { | |
msg += listarFilmesDoGenero("Você vai preferir filmes da Pixar", filmesDaPixar); | |
} | |
break; | |
} | |
case '3': { | |
msg += listarFilmesDoGenero(todosOsGeneros[2], todosOsFilmes[2]); | |
break; | |
} | |
case '0': { | |
msg += listarGeneros(todosOsGeneros, todosOsFilmes); | |
break; | |
} | |
default: JOptionPane.showMessageDialog(null, "Opção inválida"); | |
} | |
JOptionPane.showMessageDialog(null, msg); | |
System.exit(0); | |
} | |
public static String listarGeneros(String[] todosOsGeneros, String[][] todosOsFilmes) { | |
String saida = "Todos os Gêneros\n\n"; | |
for (int i = 0; i < todosOsFilmes.length; i++) { | |
saida += listarFilmesDoGenero(todosOsGeneros[i], todosOsFilmes[i]); | |
} | |
return saida; | |
} | |
public static String listarFilmesDoGenero(String genero, String[] filmes) { | |
String saida = "\n" + genero + ":\n"; | |
for (int i = 0; i < filmes.length; i++) { | |
saida += "\t\t" + filmes[i] + "\n"; | |
} | |
return saida; | |
} | |
public static boolean temIdadeParaAssistirFilmesDeTerror() { | |
int idade = Integer.parseInt(JOptionPane.showInputDialog("Quantos anos você tem?")); | |
return idade > 10; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Gratidão irmão!