Question

In: Computer Science

Code in C# Part 1 Build a Series class that has the following attributes and behaviors:...

Code in C#

Part 1

Build a Series

class that has the following attributes and behaviors:

Attributes

1.) A name -- this can be any string value (i.e. “Firefly”)

2.) A number of episodes -- this can be any non-negative integer value

3.) An episode length -- this can be a double value, in hours, representing the length of an episode (i.e. 0.5 for a half-hour episode, or 0.37 for a 23 minute episode)

4.) A forKids attribute that holds a boolean value representing whether the show is suitable for kids. A boolean value true means the show is kid-friendly.

Behaviors

1.)Create a method named GetViewingHours that returns the total amount of hours of content for this series.  This can be calculated by multiplying the number of episodes by the episode length.

2.) Create a method named PrintDetails that prints to the console the name, number of episodes, and the length of each episode.

Part 2

: In Main(), create an application that allows for the following:

1.) Output a line of text that shows the name of your Streaming Service.

2.) Prompt the user to enter a name of a series, the number of episodes in the series, the length of each episode, and whether or not the series is kid-friendly.  For simplicity, assume each episode of the series has the same length.

3.) Keep prompting the user to enter more series’ information until the total viewing hours available is greater than 1000 hours. (This means your channel has ~ 2 years of content if consumed at 1.5 hours a day).

4.) After all series have been entered, print out the details of all kid-friendly series.

5.) After all series have been entered, print the name of the series with the most episodes.

6.)After all series have been entered, print the average length of each series

Solutions

Expert Solution

/* C # program that prompts user to enter the name of the series,
* number of episodes, and length of the each episode. Then
* print the most viewed episode, average length of the episode,
* kids friendly episodes to console output */

//Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Series
{
    class Program
    {
        static void Main(string[] args)
        {
            string name;
             int numEpisodes;
             double length;
             string userInput;
             bool forKids;
            //create a List of Series class
            List<Series> seriesList = new List<Series>();
            Console.WriteLine("Live streaming company ltd");
            int MAX_HOURS = 1000;
            int totalHours = 0;


            //Loop until hours hours less than MAX_HOURS
            while (totalHours < MAX_HOURS)
            {
                Console.Write("Enter name of Series: ");
                name = Console.ReadLine();
                Console.Write("Enter # of episodes: ");
                int.TryParse(Console.ReadLine(), out numEpisodes);
                Console.Write("Enter length of each episode: ");
                double.TryParse(Console.ReadLine(), out length);

                Console.Write("Enter y for kids friendly or n for not kids friendly ");
                userInput = Console.ReadLine();

                if (userInput.Equals("y") || userInput.Equals("Y"))
                    forKids = true;
                else
                    forKids = false;
                //create a series object with name, number of episodes, length and forkids
                Series series = new Series(name, numEpisodes, length, forKids);

                seriesList.Add(series );
                //add total hours to total hours
                totalHours+=series.GetViewingHours();
            }
            //calling methods
            Console.WriteLine("Printing most episodes ");
            printMostEpisodes(seriesList);
            Console.WriteLine();
            Console.WriteLine("Printing kids friendly episodes ");
            printKidsFriendly(seriesList);
            Console.WriteLine();
            Console.WriteLine("Printing aveage length of episodes ");
            printAverageLength(seriesList);

            Console.ReadLine();
        }
        /*Method to print the average length of the series */
        public static void printAverageLength(List<Series> seriesList)
        {
            for (int index = 0; index < seriesList.Count; index++)
            {
                Console.WriteLine("Name : {0} ", seriesList.ElementAt(index).Name );
                Console.WriteLine("# of episodes : {0} ", seriesList.ElementAt(index).NumEpisodes );
                Console.WriteLine("Average length of episode : {0:#.##} ",
                    seriesList.ElementAt(index).NumEpisodes / seriesList.ElementAt(index).Length);
            }       

        }//end of method
        /*Method to display the most episodes of the series */
        public static void printMostEpisodes(List<Series> seriesList)
        {
            Series mostEpisodeSeries = seriesList.ElementAt(0);
            for(int index=1;index<seriesList.Count ;index++)
            {
                if (seriesList.ElementAt(index).NumEpisodes >mostEpisodeSeries.NumEpisodes)
                {
                    mostEpisodeSeries = seriesList.ElementAt(index);
                }
            }

            mostEpisodeSeries.PrintDetails();

        }//end of method

        /*Method to display only kids friendly*/
        public static void printKidsFriendly(List<Series> seriesList)
        {
            foreach (var item in seriesList)
            {
                if (item.KidsFriendly)
                {
                    item.PrintDetails();
                }
            }
        }//end of method
    }
}
------------------------------------------------------------------------------------------------------

//Series.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Series
{
    class Series
    {
        private string name;
        private int numEpisodes;
        private double length;
        private bool forKids;

        public Series(string name, int numEpisodes,
            double length, bool forKids)
        {
            this.name = name;
            this.numEpisodes = numEpisodes;
            this.length = length;
            this.forKids = forKids;
        }

        public string Name
        {
            set { value = name; }
            get { return name; }
        }

        public double Length
        {
            set { value = length; }
            get { return length; }
        }

        public bool KidsFriendly
        {
            set { value = forKids; }
            get { return forKids; }
        }

        public int NumEpisodes
        {
            set { value = numEpisodes ; }
            get { return numEpisodes; }
        }

        public int GetViewingHours()
        {
            int totalHours = 0;
            length = Math.Ceiling(length * 60);
            totalHours = (int)(numEpisodes * length);
            return totalHours;
        }
          public void PrintDetails()
        {
            Console.WriteLine("Name : {0} ", name);
            Console.WriteLine("# of episodes : {0} ", numEpisodes );
            Console.WriteLine("Length of Each episode : {0} ", length.ToString("F2") );
        }
    }
}

------------------------------------------------------------------------------------------------------

Sample Output:


Related Solutions

C++ Consider a class Movie that information about a movie. The class has the following attributes:...
C++ Consider a class Movie that information about a movie. The class has the following attributes: • The movie name • The MPAA rating (for example, G, PG, PG-13, R) • Array of size 5 called Ratings, each index will hold the following. [0] The number of people that have rated this movie as a 1 (Terrible) [1] The number of people that have rated this movie as a 2 (Bad) [2] The number of people that have rated this...
For the following two questions you need to provide a code in C 1. Build a...
For the following two questions you need to provide a code in C 1. Build a double linked list with 5 in the first node following the instructions: Insert a node with 3 at the top of the list Insert a node with 10 at the bottom of the list Insert a node with 7 between nodes with 5 and 10 2. Start deleting nodes from the list in the following order; Delete the node with 7 Delete the node...
C++ The following is a specification of three classes: Class Vehicle:       Attributes:       Age, an...
C++ The following is a specification of three classes: Class Vehicle:       Attributes:       Age, an integer à The age of the vehicle       Price, a float à The price of the vehicle       Behaviors: Vehicle() à default constructor sets age=0, and price=0.0 setAge()   à Takes an integer parameter, returns nothing setPrice() à Takes a float parameter, returns nothing getAge()   à Takes no parameters, returns the vehicle’s age getPrice() à Takes no parameters, returns the vehicle’s price End Class Vehicle...
Consider a class Movie that information about a movie. The class has the following attributes: • ...
Consider a class Movie that information about a movie. The class has the following attributes: • The movie name • The MPAA rating (for example, G, PG, PG-13, R) • The number of people that have rated this movie as a 1 (Terrible) • The number of people that have rated this movie as a 2 (Bad) • The number of people that have rated this movie as a 3 (OK) • The number of people that have rated this...
In C++ Demonstrate inheritance. Create an Airplane class with the following attributes: • manufacturer : string...
In C++ Demonstrate inheritance. Create an Airplane class with the following attributes: • manufacturer : string • speed : float Create a FigherPlane class that inherits from the Airplane class and adds the following attributes: • numberOfMissiles : short
Write a Class called Module with the following attributes: module code, module name, list of lecturers...
Write a Class called Module with the following attributes: module code, module name, list of lecturers for the module (some modules may have more than one lecturer – we only want to store their names), number of lecture hours, and module description. Create a parameterised (with parameters for all of the class attributes) and a non-parameterised constructor, and have the accessor and mutator methods for each attribute including a toString method. Write a class Student with the following attributes: student...
Learning Objectives: To be able to code a class structure with appropriate attributes and methods. To...
Learning Objectives: To be able to code a class structure with appropriate attributes and methods. To demonstrate the concept of inheritance. To be able to create different objects and use both default and overloaded constructors. Practice using encapsulation (setters and getters) and the toString method. Create a set of classes for various types of video content (TvShows, Movies, MiniSeries). Write a super or parent class that contains common attributes and subclasses with unique attributes for each class. Make sure to...
1. Convert the following code shown below to C++ code: public class HighwayBillboard { public int...
1. Convert the following code shown below to C++ code: public class HighwayBillboard { public int maxRevenue(int[] billboard, int[] revenue, int distance, int milesRes) { int[] MR = new int[distance + 1]; //Next billboard which can be used will start from index 0 in billboard[] int nextBillBoard = 0; //example if milesRes = 5 miles then any 2 bill boards has to be more than //5 miles away so actually we can put at 6th mile so we can add...
Given the following Java code: class C { public int foo(C p) { return 1; }...
Given the following Java code: class C { public int foo(C p) { return 1; } } class D extends C { public int foo(C p) { return 2; } public int foo(D p) { return 3; } } C p = new C(); C q = new D(); D r = new D(); int i = p.foo(r); int j = q.foo(q); int k = q.foo(r); (Remember that in Java every object is accessed through a pointer and that methods...
Note- can you rewrite the code in C++. Circle Class c++ code Write a circle class...
Note- can you rewrite the code in C++. Circle Class c++ code Write a circle class that has the following member variables: • radius: a double • pi: a double initialized with the value 3.14159 The class should have the following member functions: • Default Constructor. A default constructor that sets radius to 0.0. • Constructor. Accepts the radius of the circle as an argument . • setRadius. A mutator function for the radius variable. • getRadius. An acccssor function...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT