Question
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
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
{ 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
static List
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
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
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started