Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

using System; using System.Collections.Generic; namespace UpdatedConsoleAssignment3ForCA5 //ConsoleAssignment3Redo namespace, this contains all of my classes. { class MovieTimeProgram //class MovieTimeProgram is the name of the list

using System; using System.Collections.Generic;

namespace UpdatedConsoleAssignment3ForCA5 //ConsoleAssignment3Redo namespace, this contains all of my classes. { class MovieTimeProgram //class MovieTimeProgram is the name of the list of methods below. This one class is all I used to show my answers on the Console. { static void Main(string[] args) // This function is what keeps the list going, or prints out the final movie options. { System.Collections.Generic.List title = new List(); // declares three lists for the title, year and minutes. List year = new List(); List minutes = new List();

while (true) // this is what makes it so the program will just keep accepting movie data until the user decides they want to see what movies fit their time. { string quit; // this is creating the variable "quit".

Movie_info(title, year, minutes); // calls to the funtion "Movieinfo" to have the user keep adding movie info. Console.Write("Enter 'q' to quit and enter your max runtime. Enter anything else to keep adding to the list: "); //prints the user their options.

quit = Console.ReadLine(); //this function reads what the user answered, the if statement is making the variable "quit" = "q". if (quit == "q") //if the user enters "q" the program will move on to the next step . break; }

static void Movie_info(List title, List year, List minutes) // function "Movieinfo" is making a list out of the entered titles, years, and runtimes that the user provides.

{ Console.Write("Please tell me the name of the movie : "); string Moviename = Console.ReadLine(); // gives the variable "Moviename" the name the user enters.

string Movieyear; // these variables are required for the convert functions to work. Readline cannot read an int string Movietime; // so we must store it on a variable that can be converted to a number for the Year/Runtime.

bool validMovieYear = false; // enter the while loop

while (validMovieYear == false) // loops until the user enters a valid answer { Console.Write("Please enter the year the movie was made : ");

validMovieYear = true; //Once a valid value is entered the loop will end. (will change to false when an error happens.

try // atttempts to run the code { Movieyear = Console.ReadLine(); //Movieyear is the variable that we are storing the user entered movie year on. int Year = Convert.ToInt32(Movieyear); //this is giving the Year value the converted Movieyear variable's stored data

year.Add(Year); // this is adding the users entered year to our year list. } catch (Exception ex) // if code in the try block fails, this code will run. If does not fail it will not run this. { Console.WriteLine(ex.Message); Console.WriteLine("Please enter a number. "); // this is the eror message that displays. validMovieYear = false; } }

bool validMovieRuntime = false; // enter the while loop

while (validMovieRuntime == false) // loops until the user enters a valid answer { Console.Write("Please enter the runtime (minutes) of the movie : ");

validMovieRuntime = true; //Once a valid value is entered the loop will end. (will change to false when an error happens. try { Movietime = Console.ReadLine(); //Movietime is the variable that we are storing the user entered movie runtime on. int Minutes = Convert.ToInt32(Movietime); //this is giving the Minutes value the converted Movietime variable's stored data

minutes.Add(Minutes); // this is adding the users entered minutes to our minutes list. } catch (Exception ex) // if code in the try block fails, this code will run. If does not fail it will not run this. { Console.WriteLine(ex.Message); Console.WriteLine("Please enter a number. "); // this is the eror message that displays. validMovieRuntime = false; } }

title.Add(Moviename); // this is adding the users entered movie name to our title list. }

static List TitleOptions(List title, List minutes, int runtime) // function to filter the movie titles that fit the max minute. { List Movietitles = new List(); // declaring Movietitles list. This is the function that makes a list of the titles that fit the desired runtime for (int x = 0; x < minutes.Count; x++) // This is used for going through the minutes of each movie and continuing to go down the list. { if (minutes[x] <= runtime) // This is the function that decides if the movie title will be added to the list { Movietitles.Add(title[x]); // This adds the title to the Movietitles list. } } return Movietitles; // This will give the movie titles that fit the runtime when called upon. }

static List YearOptions(List year, List minutes , int runtime) // function to filter the movie years that fit the max minutes { List Movieyears = new List(); // declaring Movieyears list. This is the function that makes a list of the titles that fit the desired runtime

for (int x = 0; x < minutes.Count; x++) // This is used for going through the minutes of each movie and continuing to go down the list { if (minutes[x] <= runtime) // This is the function that decides if the movie year will be added to the list. { Movieyears.Add(year[x]); // This adds the year to the Movieyears list. } } return Movieyears; // This will give the movie years that fit the runtime when called upon. } static List MaxRuntime(List minutes, int runtime) // function MaxRuntime is going through all of the movie runtimes and making a list of the movies that fit the desired runtime. { List Movieruntime = new List(); // declaring Movieyears list. This is the function that makes a list of the titles that fit the desired runtime

for (int i = 0; i < minutes.Count; i++) // This is used for going through the minutes of each movie and continuing to go down the list. { if (minutes[i] <= runtime) // This is the function that decides if the movie runtime will be added to the list. { Movieruntime.Add(minutes[i]); //This adds the runtime to the Movieruntime list. } } return Movieruntime; // This will give the movie runtimes that fit the runtime when called upon. }

bool validDesiredRuntime = false; // enter the while loop string desiredruntime; //this is creating the variable "desiredruntime"

while (validDesiredRuntime == false) // loops until the user enters a valid answer { Console.WriteLine(); Console.Write("Please enter the max runtime (minutes) you would like watch: "); // prints the directions to the user

validDesiredRuntime = true; //Once a valid value is entered the loop will end. (will change to false when an error happens. try { desiredruntime = Console.ReadLine(); //this reads what the user enters for their max runtime int runtime = Convert.ToInt32(desiredruntime); //this takes the variable "desiredruntime" and converts it into an integer. The integer is what the value is for the variable "runtime".

List title_output = TitleOptions(title, minutes, runtime); // call to function "TitleOptions" to get the filtered list of movie titles. List year_output = YearOptions(year, minutes, runtime); // call to function "YearOptions" to get the filtered list of movie years. List minutes_output = MaxRuntime(minutes, runtime); // call to function "MaxRuntime" to get the filtered list of movie runtimes.

Console.WriteLine(); Console.Write("The movies that fit your desired runtime are: ");

for (int x = 0; x < title_output.Count; x++) //this goes down the TitleOptions list and gets the movies that fit the runtime. { Console.Write("{0}({1}),{2} min ", title_output[x], year_output[x], minutes_output[x]); //This will print out the movie titles, years, and runtimes that all fit in a list. }

} catch (Exception ex) // if code in the try block fails, this code will run. If does not fail it will not run this. { Console.WriteLine(ex.Message); Console.WriteLine("Please enter a number. "); // this is the eror message that displays. validDesiredRuntime = false;

} } } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Domain Transfer Learning With 3q Data Processing

Authors: Ahmed Atif Hussain

1st Edition

B0CQS1NSHF, 979-8869061805

More Books

Students also viewed these Databases questions

Question

what are the communication system requirements for AUV

Answered: 1 week ago