Esse exercício eu vou realizá-lo por etapas. Inicialmente, vou focar em resolver a solução da 1 e da 2 e depois partir para a expansão do sistema com a 3 e 4.
1-2
Filme.cs
namespace Alura.Filmes;
class Filme {
private List<string> listaElenco = new();
public string? Titulo {get;set;}
public int Duracao {get;set;}
public Filme(List<string> elenco, string? titulo, int duracao) {
listaElenco = elenco;
Titulo = titulo;
Duracao = duracao;
}
public void ExibirInformacoes() {
Console.Clear();
Console.WriteLine("=======================");
Console.WriteLine($"Título: {Titulo}");
Console.WriteLine($"Duração: {Duracao} segundos.");
Console.WriteLine($"Elenco");
listaElenco.ForEach(ator => Console.WriteLine($"- {ator}"));
Console.WriteLine("=======================");
Console.ReadKey();
}
}
Program.cs
using Alura.Filmes;
var filme1 = new Filme (
new List<string> { "Tim Robbins", "Morgan Freeman", "Bob Gunton" },
"Um Sonho de Liberdade",
8520
);
var filme2 = new Filme (
new List<string> { "Marlon Brando", "Al Pacino", "James Caan" },
"O Poderoso Chefão",
10500
);
var filme3 = new Filme (
new List<string> { "Christian Bale", "Heath Ledger", "Aaron Eckhart" },
"Batman: O Cavaleiro das Trevas",
9120
);
var filme4 = new Filme (
new List<string> { "Elijah Wood", "Ian McKellen", "Viggo Mortensen" },
"O Senhor dos Anéis: A Sociedade do Anel",
10680
);
var filme5 = new Filme (
new List<string> { "Leonardo DiCaprio", "Joseph Gordon-Levitt", "Elliot Page" },
"A Origem",
8880
);
var listaFilmes = new List<Filme>() {filme1, filme2, filme3, filme4, filme5};
listaFilmes.ForEach(filme => filme.ExibirInformacoes());