Question: USING JAVA Create a class called MovieReducerExtremes that implements MediaReducer. Implement a reducer that takes a movie list and an option (newest or oldest), then
USING JAVA
Create a class called MovieReducerExtremes that implements MediaReducer. Implement a reducer that takes a movie list and an option ("newest" or "oldest"), then return the newest or oldest movie as appropriate.Submit both the MovieReducerExtremes and the Movie class from the first question.
/////Required Output:///////
Newest 2014 AKA Jessica Jones Action Oldest 1936 Cabaret Music
Given Files:
Movie.java
public class Movie extends Media { public Movie(String name, int year, String genre) { super(name, year, genre); } public String getEra() { if (getYear() >= 2000) { return "New Millennium Era"; } else if (getYear() >= 1977) { return "Modern Era"; } else if (getYear() >= 1955) { return "Change Era"; } else if (getYear() >= 1941) { return "Golden Era"; } return "Pre-Golden Era"; } public boolean wasReleasedAfter(Media other) { return getYear() > other.getYear(); } public boolean wasReleasedBeforeOrInSameYear(Media other) { return getYear() Demo3.java
import java.io.FileNotFoundException; import java.util.ArrayList; public class Demo3 { public static void main(String[] args) throws FileNotFoundException { ArrayList movies = MovieLoader.loadAllMovies(); MediaReducer op = new MovieReducerExtremes(); System.out.println("Newest"); System.out.println(op.reduce(movies, "Newest")); System.out.println("Oldest"); System.out.println(op.reduce(movies, "Oldest")); } } Media.java public abstract class Media { private String name; private int year; private String genre; public Media(String n, int y, String g) { name = n; year = y; genre = g; } public String getName() { return name; } public int getYear() { return year; } public String getGenre() { return genre; } public String toString() { return String.format("%5d %-55s %-15s", year, name, genre); } //if the media was released on or after the year 2000, return New Millennium Era //if the media was released on or after the year 1977, return Modern Era //if the media was released on or after the year 1955, return Change Era //if the media was released on or after the year 1941, return Golden Era //in any other situation, return Pre-Golden Era public abstract String getEra(); //return true if this media has a greater release year than the other's public abstract boolean wasReleasedAfter(Media other); //return true if this media was a lesser or equal release yearn than the other's public abstract boolean wasReleasedBeforeOrInSameYear(Media other); } MovieLoader.java
import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; public class MovieLoader { public static ArrayList loadAllMovies() throws FileNotFoundException { File f = new File("movie_list.txt"); Scanner inputFile = new Scanner(f); ArrayList result = new ArrayList(); while (inputFile.hasNextLine()) { String name = inputFile.nextLine(); int year = inputFile.nextInt(); //skip new line inputFile.nextLine(); String genre = inputFile.nextLine(); Media m = new Movie(name, year, genre); result.add(m); } return result; } } MediaReducer
import java.util.ArrayList; public interface MediaReducer { public String reduce(ArrayList list, String key); } A couple from the movie_list.txt
!Next? 1994 Documentary #1 Single 2006 Reality-TV #ByMySide 2012 Drama #Follow 2011 Mystery #nitTWITS 2011 Comedy $#*! My Dad Says 2010 Comedy $1,000,000 Chance of a Lifetime 1986 etc..
CURRENT CODE
import java.util.ArrayList;
public class MovieReducerExtremes implements MediaReducer {
@Override
public String reduce(ArrayList list, String key) {
// checking if the key is newest or oldest
if (key.equalsIgnoreCase("newest")) {
// a variable to store the newest movie
Media newest = null;
// looping through each Media in list
for (int i = 0; i
Media m = (Media) list.get(i);
// if newest is not initialized or m is newer than newest,
// updating newest
if (newest == null || m.getYear() > newest.getYear()) {
newest = m;
}
}
// will invoke and return String returned by toString() in Media
// class
return "" + newest;
} else if (key.equalsIgnoreCase("oldest")) {
Media oldest = null;
// looping through each Media in list
for (int i = 0; i
Media m = (Media) list.get(i);
// if oldest is not initialized or m is older than oldest,
// updating oldest
if (oldest == null || m.getYear()
oldest = m;
}
}
return "" + oldest;
}
// invalid key
return null;
}
}
Create a class called MovieReducerExtremes that implements MediaReducer. Implement a reducer that takes a movie list and an option ('newest' or 'oldest"), then return the newest or oldest movie as appropriate, Submit both the MovieReducerExtremes and the Movie class from the first question. Test Case 1 - Failed Files in the same directory MovieLoader.java Demo3.java MediaReducer.java movie_list.txt Media.java Your Program's Output Required Output Newest 2014 AKA Jessica Jones Action Oldest in 1936 Cabaret Music Newest 2014 AKA Jessica Jones Action In Oldest 1936 Berlin 1936: Games of the XI Olympiad Sport HyperGrade, LLC 2020 Create a class called MovieReducerExtremes that implements MediaReducer. Implement a reducer that takes a movie list and an option ('newest' or 'oldest"), then return the newest or oldest movie as appropriate, Submit both the MovieReducerExtremes and the Movie class from the first question. Test Case 1 - Failed Files in the same directory MovieLoader.java Demo3.java MediaReducer.java movie_list.txt Media.java Your Program's Output Required Output Newest 2014 AKA Jessica Jones Action Oldest in 1936 Cabaret Music Newest 2014 AKA Jessica Jones Action In Oldest 1936 Berlin 1936: Games of the XI Olympiad Sport HyperGrade, LLC 2020 Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
