Question

Create a class called MovieReducerLength that implements MediaReducer. Implement a reducer that takes a movie list...

Create a class called MovieReducerLength that implements MediaReducer. Implement a reducer that takes a movie list and a String length, then return a String that contains all the movies that have a name of the given length.

Files Given:

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() <= other.getYear();
    }
}

Demo4.java
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;

public class Demo4 {

    public static void main(String[] args) throws FileNotFoundException {
        ArrayList movies = MovieLoader.loadAllMovies();

        MediaReducer op = new MovieReducerLength();

        Scanner keyboard = new Scanner(System.in);
        System.out.println("Enter a length");
        String length = keyboard.nextLine();
        System.out.println(op.reduce(movies, length));
    }
}
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
Game-Show
$100 Makeover
2010
Reality-TV
$100 Taxi Ride
2001
Documentary
$100,000 Name That Tune
1984
Game-Show
$100,000 Name That Tune
1984
Music
$2 Bill
2002
Documentary
$2 Bill
2002
Music
$2 Bill
2002
Music
$2 Bill
2002
Music
$2 Bill
2002
Music
$25 Million Dollar Hoax
2004
Reality-TV
$40 a Day
2002
Documentary
$5 Cover
2009
Drama
$5 Cover: Seattle
2009
Drama
$50,000 Letterbox
1980
Game-Show
$9.99
2003
Adventure
$weepstake$
1979
Drama
' Horse Trials '
2011
Sport
'80s Videos: A to Z
2009
Music
'Allo 'Allo!
1982
Comedy
'Allo 'Allo!
1982
War
'Conversations with My Wife'
2010
Comedy
'Da Kink in My Hair
2007
Comedy
'Da Kink in My Hair
2007
Drama
'More strasti'
2000
Romance
'Ons Sterrenkookboek'
2007
Documentary
'Orrible
2001
Comedy
'Orrible
2001
Crime
'Orrible
2001
Drama
'S ann an Ile
2009
Documentary
'Sang linggo nAPO sila
1995
Game-Show
'Sang linggo nAPO sila
1995
Musical
'T Wilhelmina
1975
Comedy
'Til Death Do Us Part
2006
Crime
'Til Death Do Us Part
2006
Drama
'Til Death Do Us Part
2006
Fantasy
'Til Death Do Us Part
2006
Romance
'Til Death Do Us Part
2006
Thriller
'Til Death
2006
Comedy
'Untold
2004
Documentary
'Wag kukurap
2004
Horror
'Way Out
1961
Drama
'Way Out
1961
Horror
'Way Out
1961
Sci-Fi
'n Shrink
2009
Comedy
't Is maar TV
1999
Comedy
't Is maar TV
1999
Game-Show
't Is maar een spel
2002
Comedy
't Is maar een spel
2002
Game-Show
't Schaep Met De 5 Pooten
1969
Comedy
't Schaep Met De 5 Pooten
2006
Comedy
't Schaep Met De 5 Pooten
2006
Drama
't Zal je gebeuren...
1998
Drama
't Zonnetje in huis
1993
Comedy
(S)truth
1999
Drama
+ Clair
2001
Documentary
+ Emprendedores mi+d
2010
Documentary
+ Investigadores
2008
Documentary
+ de cin�ma
2001
Documentary
+ de cin�ma
2001
News
... ins Gr�ne! Das Stadt-Land-Lust-Magazin
2010
Documentary
... und basta!
2006
Comedy
... und basta!
2006
Music
... und die Tuba bl�st der Huber
1981
Comedy

Required Output

Homework Answers

Answer #1
class MovieReducerLength implements MediaReducer {

        @Override
        public String reduce(ArrayList list, String key) {

                String result = "";
                for (int i = 0; i < list.size(); i++) {

                        Media m = ((Media) list.get(i));
                        if (m.getName().length() == Integer.parseInt(key)) {
                                if (!result.isEmpty()) {
                                        result += ", ";
                                }
                                result += m.getName();
                        }

                }

                return result;
        }

}
**************************************************

Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.

Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Create a class called MovieReducerLength that implements MediaReducer. Implement a reducer that takes a movie list...
Create a class called MovieReducerLength that implements MediaReducer. Implement a reducer that takes a movie list and a String length, then return a String that contains all the movies that have a name of the given length. Submit both the MovieReducerLength and the Movie class from the first question. Files Given: 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...
Based on Movie package example, you will create a package about your favorite TV series and...
Based on Movie package example, you will create a package about your favorite TV series and provide the plot() Readme.txt: Explain how you apply polymorphism in your program package Movie; public class MovieTester { public static void main(String[] args) { for(int i = 1; i < 11; i++){ Movie movie = randomMovie(); System.out.println("Movie # " + i + ": " + movie.getTitle() + ", Genre: " + movie.getGenre() + '\n' +"Plot: " + movie.plot()); } } public static Movie randomMovie(){...
Delta airlines case study Global strategy. Describe the current global strategy and provide evidence about how...
Delta airlines case study Global strategy. Describe the current global strategy and provide evidence about how the firms resources incompetencies support the given pressures regarding costs and local responsiveness. Describe entry modes have they usually used, and whether they are appropriate for the given strategy. Any key issues in their global strategy? casestudy: Atlanta, June 17, 2014. Sea of Delta employees and their families swarmed between food trucks, amusement park booths, and entertainment venues that were scattered throughout what would...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT