- Crear una clase base CatalogItem para almacenar atributos comunes como nombre, código, categoría y tamaño.
- Crear tres clases derivadas: Movie, MusicFile y Software.
- Implementar los atributos adicionales necesarios para películas y archivos de música.
- Definir un método Play() para Movie y MusicFile, pero dejarlo sin implementar.
- Definir un método RetrieveInformation() para la futura integración con una base de datos en línea.
- En el método Main, crear matrices de cada tipo y mostrar sus detalles.
Crear el diagrama de clases y, a continuación, con Visual Studio, un proyecto y las clases correspondientes para una utilidad de catálogo:
Podrá almacenar información sobre archivos de música, películas y programas informáticos.
Para cada elemento, debe almacenar: nombre, código, categoría y tamaño. Para las películas, también debe contener el director, el actor principal y la actriz principal. Para los archivos de música, el cantante y la duración (en segundos).
Para música y películas, debe tener un método Play (aún no implementado) y también un método RetrieveInformation, que (en una versión posterior) se conectará a un servidor de Internet para obtener información al respecto.
using System;
// Base class representing a general catalog item
class CatalogItem
{
// Common attributes for all catalog items
public string Name { get; set; }
public int Code { get; set; }
public string Category { get; set; }
public double Size { get; set; } // Size in MB
// Constructor to initialize catalog items
public CatalogItem(string name, int code, string category, double size)
{
Name = name;
Code = code;
Category = category;
Size = size;
}
// Method to display the item details
public virtual void ShowData()
{
Console.WriteLine($"Name: {Name}, Code: {Code}, Category: {Category}, Size: {Size} MB");
}
}
// Derived class representing a movie
class Movie : CatalogItem
{
// Additional attributes specific to movies
public string Director { get; set; }
public string MainActor { get; set; }
public string MainActress { get; set; }
// Constructor initializing both base and specific attributes
public Movie(string name, int code, string category, double size, string director, string mainActor, string mainActress)
: base(name, code, category, size)
{
Director = director;
MainActor = mainActor;
MainActress = mainActress;
}
// Overriding ShowData to include movie-specific details
public override void ShowData()
{
base.ShowData();
Console.WriteLine($"Director: {Director}, Main Actor: {MainActor}, Main Actress: {MainActress}");
}
// Placeholder for Play method
public void Play()
{
Console.WriteLine("Playing the movie... (not implemented yet)");
}
// Placeholder for RetrieveInformation method
public void RetrieveInformation()
{
Console.WriteLine("Retrieving movie information... (not implemented yet)");
}
}
// Derived class representing a music file
class MusicFile : CatalogItem
{
// Additional attributes specific to music files
public string Singer { get; set; }
public int Length { get; set; } // Length in seconds
// Constructor initializing both base and specific attributes
public MusicFile(string name, int code, string category, double size, string singer, int length)
: base(name, code, category, size)
{
Singer = singer;
Length = length;
}
// Overriding ShowData to include music file details
public override void ShowData()
{
base.ShowData();
Console.WriteLine($"Singer: {Singer}, Length: {Length} seconds");
}
// Placeholder for Play method
public void Play()
{
Console.WriteLine("Playing the music file... (not implemented yet)");
}
// Placeholder for RetrieveInformation method
public void RetrieveInformation()
{
Console.WriteLine("Retrieving music file information... (not implemented yet)");
}
}
// Derived class representing a software application
class Software : CatalogItem
{
// Constructor initializing base class attributes
public Software(string name, int code, string category, double size)
: base(name, code, category, size)
{
}
}
// Main program
class Program
{
static void Main()
{
// Create an array of movies
Movie[] movies = new Movie[]
{
new Movie("Inception", 101, "Sci-Fi", 1500, "Christopher Nolan", "Leonardo DiCaprio", "Ellen Page"),
new Movie("Titanic", 102, "Romance", 1900, "James Cameron", "Leonardo DiCaprio", "Kate Winslet")
};
// Create an array of music files
MusicFile[] musicFiles = new MusicFile[]
{
new MusicFile("Bohemian Rhapsody", 201, "Rock", 5.2, "Queen", 355),
new MusicFile("Shape of You", 202, "Pop", 4.7, "Ed Sheeran", 240)
};
// Create an array of software applications
Software[] softwares = new Software[]
{
new Software("Microsoft Word", 301, "Office", 1024),
new Software("Adobe Photoshop", 302, "Design", 2048)
};
// Display details of all movies
Console.WriteLine("Movies:");
foreach (var movie in movies)
{
movie.ShowData();
Console.WriteLine();
}
// Display details of all music files
Console.WriteLine("Music Files:");
foreach (var music in musicFiles)
{
music.ShowData();
Console.WriteLine();
}
// Display details of all software applications
Console.WriteLine("Software Applications:");
foreach (var software in softwares)
{
software.ShowData();
Console.WriteLine();
}
// Example of calling Play() and RetrieveInformation()
Console.WriteLine("Testing Play and RetrieveInformation methods:");
movies[0].Play();
movies[0].RetrieveInformation();
musicFiles[0].Play();
musicFiles[0].RetrieveInformation();
}
}
Output
Movies:
Name: Inception, Code: 101, Category: Sci-Fi, Size: 1500 MB
Director: Christopher Nolan, Main Actor: Leonardo DiCaprio, Main Actress: Ellen Page
Name: Titanic, Code: 102, Category: Romance, Size: 1900 MB
Director: James Cameron, Main Actor: Leonardo DiCaprio, Main Actress: Kate Winslet
Music Files:
Name: Bohemian Rhapsody, Code: 201, Category: Rock, Size: 5.2 MB
Singer: Queen, Length: 355 seconds
Name: Shape of You, Code: 202, Category: Pop, Size: 4.7 MB
Singer: Ed Sheeran, Length: 240 seconds
Software Applications:
Name: Microsoft Word, Code: 301, Category: Office, Size: 1024 MB
Name: Adobe Photoshop, Code: 302, Category: Design, Size: 2048 MB
Testing Play and RetrieveInformation methods:
Playing the movie... (not implemented yet)
Retrieving movie information... (not implemented yet)
Playing the music file... (not implemented yet)
Retrieving music file information... (not implemented yet)
Código de ejemplo copiado