7.07 - Catalog

Objetive
Create the classes diagram and then, using Visual Studio, a project and the corresponding classes for a catalog utility:

It will be able to store information about music files, films and computer programs.
For each item, it must store: name, code, category and size. For films it must also hold the director, the main actor and the main actress. For music files, the singer and the length (in seconds).
For music and movies it must have a method "Play" (not implemented yet) and also a method "RetrieveInformation", which will (in a later version) connect to an internet server to get information about it.
Use inheritance if needed. In "Main", create arrays of each kind of object.


Resolution
using System;
namespace Catalog
{
    class TestItem
    {
        static void Main()
        {
            Film[] myFilms = new Film[3];
            Music[] myMusic = new Music[3];
            ComputerProgram[] myComputerProgram = new ComputerProgram[3];
        }
    }

    public class Item 
    {
        protected string name;
        protected string code;
        protected string category;
        protected string size;

        public Item()
        {
        }
        public Item (string name, string code, string category, string size) 
        {
            this.name = name;
            this.code = code;
            this.category = category;
            this.size = size;
        }

        public string Name 
        {
            get { return name; }
            set { name = value; }
        }
        public string Code
        {
            get { return code; }
            set { code = value; }
        }
        public string Category
        {
            get { return category; }
            set { category = value; }
        }
        public string Size
        {
            get { return size; }
            set { size = value; }
        }
    }

    public class Film : Item
    {
        protected string director;
        protected string mainActor, mainActress;

        public Film() 
        {

        }
        public Film(string director, string mainActor, string mainActress) 
        {
            this.director = director;
            this.mainActor = mainActor;
            this.mainActress = mainActress;
        }

        public string Director 
        {
            get { return director; }
            set { director = value; }
        }
        public string MainActor
        {
            get { return mainActor; }
            set { mainActor = value; }
        }
        public string MainActress
        {
            get { return mainActress; }
            set { mainActress = value; }
        }

        public void Play()
        {

        }
        public void RetrieveInformation()
        {

        }
    }

    public class Music : Item
    {
        protected string singer;
        protected int length;

        public Music() 
        {

        }
        public Music (string singer, int length) 
        {
            this.singer = singer;
            this.length = length;
        }

        public string Singer 
        {
            get { return singer; }
            set { singer = value; }
        }
        public int Lenght
        {
            get { return length; }
            set { length = value; }
        }

        public void Play() 
        {

        }
        public void RetrieveInformation() 
        {

        }
    }

    public class ComputerProgram  : Item
    {

    }
}

Popular Posts