package murach.movies;
import murach.movies.MovieDB;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Scanner;
import java.util.TreeSet;
import murach.movies.Movie;
/*
* This application stores a list of 100 movies and displays them by category.
The user can enter any of the following categories to display the films in the list that match the category:
animated, drama, horror, musical, scifi
After each list is displayed, the user is asked whether to continue. If the user enters Y or y,
the program asks for another category. Otherwise, the program ends.
*/
public class MovieListerApp {
/*
* Author: Piano Hagens
* 03/13/2017
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Welcome to the Movie List Application.");
System.out.println("There are 100 movies on the list.\n");
Scanner sc = new Scanner(System.in);
String choice = "y";
ArrayList<Movie> myListOfMovies = createArrayList();
//
while (choice.equalsIgnoreCase("y"))
{
System.out.println("Here are categories: animated, drama, horror, musical, comedy, and scifi");
System.out.println();
String personMovieCategory = Validator.getRequiredString(sc, "What category are you interested in? ");
Collection<Movie> matchedMovies = new TreeSet<>();
for(Movie movie : myListOfMovies) {
if (personMovieCategory.equalsIgnoreCase(movie.getCategory()))
{
matchedMovies.add(movie);
}
}
for (Movie movie : matchedMovies)
{
System.out.println(movie.getTitle());
}
choice = Validator.getRequiredString(sc, "\nContinue? (y/n): ");
System.out.println();
}
}
//createArrayList()
public static ArrayList<Movie> createArrayList()
{
ArrayList<Movie> m;
ArrayList<Movie> creatingArrayList = new ArrayList<>();
for (int i = 0; i <= 100; i++ )
{
m = MovieDB.getAllMovies();
creatingArrayList.addAll(m);
}
return creatingArrayList;
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
package murach.movies;
import java.util.Scanner;
public class Validator
{
public static int getInt(Scanner sc, String prompt)
{
int i = 0;
boolean isValid = false;
while (!isValid)
{
System.out.print(prompt);
if (sc.hasNextInt())
{
i = sc.nextInt();
isValid = true;
}
else
{
System.out.println("Sorry! No this category has found.");
}
sc.nextLine(); // discard any other data entered on the line
}
return i;
}
public static int getIntWithinRange(Scanner sc, String prompt,
int min, int max)
{
int i = 0;
boolean isValid = false;
while (!isValid)
{
i = getInt(sc, prompt);
if (i <= min)
System.out.println(
"Error! Number must be greater than " + min);
else if (i > max)
System.out.println(
"Error! Number must be less or equal to " + max);
else
isValid = true;
}
return i;
}
public static double getDouble(Scanner sc, String prompt)
{
double d = 0;
boolean isValid = false;
while (!isValid)
{
System.out.print(prompt);
if (sc.hasNextDouble())
{
d = sc.nextDouble();
isValid = true;
}
else
{
System.out.println("Sorry! No this category has found. Try again.");
}
sc.nextLine(); // discard any other data entered on the line
}
return d;
}
public static String getRequiredString(Scanner sc, String prompt)
{
String s = "";
boolean isValid = false;
while (!isValid)
{
System.out.print(prompt);
s = sc.nextLine();
if (s == null || s.equals(""))
{
System.out.println("Sorry! No this category has found. Try again.");
}
else
{
isValid = true;
}
}
return s;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
package murach.movies;
import java.util.ArrayList;
public class MovieDB {
/*
* Use the MovieDB class that’s provided to you to get the ArrayList objects.
* To do that, you’ll need to finish the code for the getMovies methods
*/
private static ArrayList<Movie> allMovies = new ArrayList<>(100);
public static ArrayList<Movie> getAllMovies() {
allMovies.add(new Movie("Citizen Kane", "drama"));
allMovies.add(new Movie("Casablanca", "drama"));
allMovies.add(new Movie("The Godfather", "drama"));
allMovies.add(new Movie("Gone With The Wind", "drama"));
allMovies.add(new Movie("Lawrence Of Arabia", "drama"));
allMovies.add(new Movie("The Wizard Of Oz", "musical"));
allMovies.add(new Movie("The Graduate", "drama"));
allMovies.add(new Movie("On The Waterfront", "drama"));
allMovies.add(new Movie("Schindler's List", "drama"));
allMovies.add(new Movie("Singin' In The Rain", "musical"));
allMovies.add(new Movie("It's A Wonderful Life", "drama"));
allMovies.add(new Movie("Sunset Boulevard", "drama"));
allMovies.add(new Movie("The Bridge On The River Kwai", "drama"));
allMovies.add(new Movie("Some Like It Hot", "drama"));
allMovies.add(new Movie("Star Wars", "scifi"));
allMovies.add(new Movie("All About Eve", "drama"));
allMovies.add(new Movie("The African Queen", "drama"));
allMovies.add(new Movie("Psycho", "horror"));
allMovies.add(new Movie("Chinatown", "drama"));
allMovies.add(new Movie("One Flew Over The Cuckoo's Nest", "drama"));
allMovies.add(new Movie("The Grapes Of Wrath", "drama"));
allMovies.add(new Movie("2001: A Space Odyssey", "scifi"));
allMovies.add(new Movie("The Maltese Falcon", "drama"));
allMovies.add(new Movie("Raging Bull", "drama"));
allMovies.add(new Movie("E.T. The extra-terrestrial", "scifi"));
allMovies.add(new Movie("Dr. Strangelove", "drama"));
allMovies.add(new Movie("Bonnie And Clyde", "drama"));
allMovies.add(new Movie("Apocalypse Now", "drama"));
allMovies.add(new Movie("Mr. Smith Goes to Washington", "drama"));
allMovies.add(new Movie("The Treasure Of The Sierra Madre", "drama"));
allMovies.add(new Movie("Annie Hall", "comedy"));
allMovies.add(new Movie("The Godfather Part II", "drama"));
allMovies.add(new Movie("High Noon", "drama"));
allMovies.add(new Movie("To Kill A Mockingbird", "drama"));
allMovies.add(new Movie("It Happened One Night", "drama"));
allMovies.add(new Movie("Midnight Cowboy", "drama"));
allMovies.add(new Movie("The Best Years Of Our Lives", "drama"));
allMovies.add(new Movie("Double Indemnity", "drama"));
allMovies.add(new Movie("Doctor Zhivago", "drama"));
allMovies.add(new Movie("North By Northwest", "drama"));
allMovies.add(new Movie("West Side Story", "musical"));
allMovies.add(new Movie("Rear Window", "drama"));
allMovies.add(new Movie("King Kong", "horror"));
allMovies.add(new Movie("The Birth Of A Nation", "drama"));
allMovies.add(new Movie("A Streetcar Named Desire", "drama"));
allMovies.add(new Movie("A Clockwork Orange", "scifi"));
allMovies.add(new Movie("Taxi Driver", "drama"));
allMovies.add(new Movie("Jaws", "horror"));
allMovies.add(new Movie("Snow White And The Seven Dwarfs", "animated"));
allMovies.add(new Movie("Butch Cassidy And The Sundance Kid", "drama"));
allMovies.add(new Movie("The Philadelphia Story", "drama"));
allMovies.add(new Movie("From Here To Eternity", "drama"));
allMovies.add(new Movie("Amadeus", "drama"));
allMovies.add(new Movie("All Quiet On The Western Front", "drama"));
allMovies.add(new Movie("The Sound Of Music", "musical"));
allMovies.add(new Movie("M*A*S*H", "comedy"));
allMovies.add(new Movie("The Third Man", "drama"));
allMovies.add(new Movie("Fantasia", "animated"));
allMovies.add(new Movie("Rebel Without A Cause", "drama"));
allMovies.add(new Movie("Raiders Of The Lost Ark", "drama"));
allMovies.add(new Movie("Vertigo", "drama"));
allMovies.add(new Movie("Tootsie", "comedy"));
allMovies.add(new Movie("Stagecoach", "drama"));
allMovies.add(new Movie("Close Encounters Of The Third Kind", "scifi"));
allMovies.add(new Movie("The Silence Of The Lambs", "horror"));
allMovies.add(new Movie("Network", "drama"));
allMovies.add(new Movie("The Manchurian Candidate", "drama"));
allMovies.add(new Movie("An American In Paris", "drama"));
allMovies.add(new Movie("Shane", "drama"));
allMovies.add(new Movie("The French Connection", "drama"));
allMovies.add(new Movie("Forrest Gump", "drama"));
allMovies.add(new Movie("Ben-Hur", "drama"));
allMovies.add(new Movie("Wuthering Heights", "drama"));
allMovies.add(new Movie("The Gold Rush", "drama"));
allMovies.add(new Movie("Dances With Wolves", "drama"));
allMovies.add(new Movie("City Lights", "drama"));
allMovies.add(new Movie("American Graffiti", "drama"));
allMovies.add(new Movie("Rocky", "drama"));
allMovies.add(new Movie("The Deer Hunter", "drama"));
allMovies.add(new Movie("The Wild Bunch", "drama"));
allMovies.add(new Movie("Modern Times", "drama"));
allMovies.add(new Movie("Giant", "drama"));
allMovies.add(new Movie("Platoon", "drama"));
allMovies.add(new Movie("Fargo", "drama"));
allMovies.add(new Movie("Duck Soup", "comedy"));
allMovies.add(new Movie("Mutiny On The Bounty", "drama"));
allMovies.add(new Movie("Frankenstein", "horror"));
allMovies.add(new Movie("Easy Rider", "drama"));
allMovies.add(new Movie("Patton", "drama"));
allMovies.add(new Movie("The Jazz Singer", "drama"));
allMovies.add(new Movie("My Fair Lady", "musical"));
allMovies.add(new Movie("A Place In The Sun", "drama"));
allMovies.add(new Movie("The Apartment", "drama"));
allMovies.add(new Movie("Goodfellas", "drama"));
allMovies.add(new Movie("Pulp Fiction", "drama"));
allMovies.add(new Movie("The Searchers", "drama"));
allMovies.add(new Movie("Bringing Up Baby", "drama"));
allMovies.add(new Movie("Unforgiven", "drama"));
allMovies.add(new Movie("Guess Who's Coming To Dinner", "drama"));
allMovies.add(new Movie("Yankee Doodle Dandy", "musical"));
return allMovies;
}
public static ArrayList<Movie> getMovies(String category) {
ArrayList<Movie> movies = new ArrayList<>();
// TODO: add code to add all movies with the specified category
return movies;
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
package murach.movies;
/*
* Use the Movie class that’s provided to store the title and category for each movie.
*/
public class Movie implements Comparable{
private String title;
private String category;
public Movie(String title, String category) {
this.title = title;
this.category = category;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
@Override
public int compareTo(Object o)
{
Movie m = (Movie) o;
int titleCompare = this.getTitle().compareTo(m.getTitle());
if (titleCompare != 0)
return titleCompare;
else
return(this.getTitle().compareToIgnoreCase(m.getTitle()));
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////