1. Implement a main menu with options to add music, film, or program entries.
2. Create methods to input and store data for each catalog item, with fields like name, code, category, size, and additional properties for specific items like director or singer.
3. Allow the user to view all stored catalog items by selecting the appropriate menu option.
4. Ensure that each type of catalog item (music, film, program) is handled separately but within the same menu-driven interface.
Improve the Catalog program, so that "Main" displays a menu to allow entering new data of any kind, as well as displaying all the data stored.
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