1. Implementar un menú principal con opciones para añadir entradas de música, películas o programas.
2. Crear métodos para introducir y almacenar datos para cada elemento del catálogo, con campos como nombre, código, categoría, talla y propiedades adicionales para elementos específicos, como director o cantante.
3. Permitir al usuario ver todos los elementos del catálogo almacenados seleccionando la opción de menú correspondiente.
4. Asegurarse de que cada tipo de elemento del catálogo (música, película, programa) se gestione por separado, pero dentro de la misma interfaz de menús.
Mejorar el programa Catálogo para que "Principal" muestre un menú que permita introducir nuevos datos de cualquier tipo, así como mostrar todos los datos almacenados.
using System;
using System.Collections.Generic;
// Base class for catalog items
class CatalogItem
{
public string Name { get; set; }
public string Code { get; set; }
public string Category { get; set; }
public double Size { get; set; }
// Constructor
public CatalogItem(string name, string code, string category, double size)
{
Name = name;
Code = code;
Category = category;
Size = size;
}
// Display method
public virtual void Display()
{
Console.WriteLine($"Name: {Name}, Code: {Code}, Category: {Category}, Size: {Size}MB");
}
}
// Music class inherits from CatalogItem
class Music : CatalogItem
{
public string Singer { get; set; }
public double Length { get; set; }
// Constructor
public Music(string name, string code, string category, double size, string singer, double length)
: base(name, code, category, size)
{
Singer = singer;
Length = length;
}
// Display method for music
public override void Display()
{
base.Display();
Console.WriteLine($"Singer: {Singer}, Length: {Length} seconds");
}
}
// Film class inherits from CatalogItem
class Film : CatalogItem
{
public string Director { get; set; }
public string MainActor { get; set; }
public string MainActress { get; set; }
// Constructor
public Film(string name, string code, string category, double size, string director, string mainActor, string mainActress)
: base(name, code, category, size)
{
Director = director;
MainActor = mainActor;
MainActress = mainActress;
}
// Display method for film
public override void Display()
{
base.Display();
Console.WriteLine($"Director: {Director}, Main Actor: {MainActor}, Main Actress: {MainActress}");
}
}
// Program class to simulate the catalog system
class Program
{
static List catalog = new List();
static void Main()
{
bool exit = false;
while (!exit)
{
// Display menu
Console.Clear();
Console.WriteLine("Catalog Menu");
Console.WriteLine("1. Add Music");
Console.WriteLine("2. Add Film");
Console.WriteLine("3. Display All");
Console.WriteLine("4. Exit");
Console.Write("Choose an option: ");
string choice = Console.ReadLine();
switch (choice)
{
case "1":
AddMusic();
break;
case "2":
AddFilm();
break;
case "3":
DisplayAll();
break;
case "4":
exit = true;
break;
default:
Console.WriteLine("Invalid choice! Please try again.");
break;
}
}
}
// Method to add music
static void AddMusic()
{
Console.WriteLine("\nEnter Music Details:");
Console.Write("Name: ");
string name = Console.ReadLine();
Console.Write("Code: ");
string code = Console.ReadLine();
Console.Write("Category: ");
string category = Console.ReadLine();
Console.Write("Size (MB): ");
double size = double.Parse(Console.ReadLine());
Console.Write("Singer: ");
string singer = Console.ReadLine();
Console.Write("Length (seconds): ");
double length = double.Parse(Console.ReadLine());
Music music = new Music(name, code, category, size, singer, length);
catalog.Add(music);
Console.WriteLine("\nMusic added successfully!");
Console.ReadKey();
}
// Method to add film
static void AddFilm()
{
Console.WriteLine("\nEnter Film Details:");
Console.Write("Name: ");
string name = Console.ReadLine();
Console.Write("Code: ");
string code = Console.ReadLine();
Console.Write("Category: ");
string category = Console.ReadLine();
Console.Write("Size (MB): ");
double size = double.Parse(Console.ReadLine());
Console.Write("Director: ");
string director = Console.ReadLine();
Console.Write("Main Actor: ");
string mainActor = Console.ReadLine();
Console.Write("Main Actress: ");
string mainActress = Console.ReadLine();
Film film = new Film(name, code, category, size, director, mainActor, mainActress);
catalog.Add(film);
Console.WriteLine("\nFilm added successfully!");
Console.ReadKey();
}
// Method to display all catalog items
static void DisplayAll()
{
Console.WriteLine("\nAll Catalog Items:");
foreach (var item in catalog)
{
item.Display();
Console.WriteLine();
}
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
}
Output
Catalog Menu
1. Add Music
2. Add Film
3. Display All
4. Exit
Choose an option: 1
Enter Music Details:
Name: Shape of You
Code: SOE123
Category: Pop
Size (MB): 5
Singer: Ed Sheeran
Length (seconds): 233
Music added successfully!
Catalog Menu
1. Add Music
2. Add Film
3. Display All
4. Exit
Choose an option: 3
All Catalog Items:
Name: Shape of You, Code: SOE123, Category: Pop, Size: 5MB
Singer: Ed Sheeran, Length: 233 seconds
Código de ejemplo copiado