Question
This is to be written in Java. Make sure the program follows all the instructions and also works with the Rubric. Rubric. Movie.java fie: public
This is to be written in Java.
Make sure the program follows all the instructions and also works with the Rubric.
Rubric.
Movie.java fie:
public class Movie { // instance variables private int year; private String title; private String studio;
// Constructor for objects of class Movie public Movie(String title, int year, String studio) { // initialize instance variables this.title = title; this.year = year; this.studio = studio; }
public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getStudio() { return studio; } public void setStudio(String studio) { this.studio = studio; } public int getYear() { return year; }
public void setYear(int year) { this.year = year; }
public String toString() { String str = String.format("%-30s %4d %-20s", title, year, studio); return str; } }
MovieTester
import java.util.Arrays; import java.util.Collections;
public class MovieManager {
// a method to print all the movies in the array /** * @param movieArray : a Array of Type Movie */ public static void printMovies(Movie[] movieArray) { for (Movie movie : movieArray) { System.out.println(movie); } }
/** * @param movieArray : a Array of type Movie that will be sorted according to * movie-title * @param asc1des2 : 1 for ascending, 2 for descending, any other integer for * no effect */ public static void sortByTitle(Movie[] movieArray, int asc1des2) { if (asc1des2 == 1 || asc1des2 == 2) { int n = movieArray.length; for (int j = 1; j -1) && (movieArray[i].getTitle().compareTo(key.getTitle()) > 0)) { movieArray[i + 1] = movieArray[i]; i--; } movieArray[i + 1] = key; } }
if (asc1des2 == 2) { // reverse the order for descending Collections.reverse(Arrays.asList(movieArray)); } }
/** * @param movieArray : a Array of type Movie that will be sorted according to * movie-released-year * @param asc1des2 : 1 for ascending, 2 for descending, any other integer for * no effect */ public static void sortByYear(Movie[] movieArray, int asc1des2) { if (asc1des2 == 1 || asc1des2 == 2) { int n = movieArray.length; for (int j = 1; j -1) && (movieArray[i].getYear() > key.getYear())) { movieArray[i + 1] = movieArray[i]; i--; } movieArray[i + 1] = key; } }
if (asc1des2 == 2) { // reverse the order Collections.reverse(Arrays.asList(movieArray)); } }
/** * @param movieArray : a Array of type Movie that will be sorted according to * movie-studio-name * @param asc1des2 : 1 for ascending, 2 for descending, any other integer for * no effect */ public static void sortByStudio(Movie[] movieArray, int asc1des2) { if (asc1des2 == 1 || asc1des2 == 2) { int n = movieArray.length; for (int j = 1; j -1) && (movieArray[i].getStudio().compareTo(key.getStudio()) > 0)) { movieArray[i + 1] = movieArray[i]; i--; } movieArray[i + 1] = key; } }
if (asc1des2 == 2) { // reverse the order Collections.reverse(Arrays.asList(movieArray)); } }
public static void main(String[] args) { Movie[] movieArray = new Movie[10]; movieArray[0] = new Movie("Feeling Void", 2020, "VoidStudio"); movieArray[1] = new Movie("To the Basement and Back", 2021, "BeingBoredAtHomeStudio"); movieArray[2] = new Movie("To the floor and Back to Couch", 2020, "BeingBoredAtHomeStudio"); movieArray[3] = new Movie("To the Kitchen and Back", 2020, "BeingBoredAtHomeStudio"); movieArray[4] = new Movie("Trying to cook", 2020, "NothingToDoStudio"); movieArray[5] = new Movie("What Day is it?", 2020, "NoIdeaStudio"); movieArray[6] = new Movie("OnlineClasses", 2021, "DearSchoolStudio"); movieArray[7] = new Movie("My pet is Outdoor Only", 2020, "StayAtHomeStudio"); movieArray[8] = new Movie("No More Ideas Left", 1999, "ThatsEnoughtStudio"); movieArray[9] = new Movie("Ahh! Finally", 2020, "FinallyStudio");
System.out.println("Unsorted Movies are:"); printMovies(movieArray);
// demonstrating ascending sort
System.out.println(" Movies sorted according to Title in ascending are:"); sortByTitle(movieArray, 1); printMovies(movieArray);
System.out.println(" Movies sorted according to released year in ascending are:"); sortByYear(movieArray, 1); printMovies(movieArray);
System.out.println(" Movies sorted according to Studio in ascending are:"); sortByStudio(movieArray, 1); printMovies(movieArray);
// demonstrating descending
System.out.println(" Movies sorted according to Title in descending are:"); sortByTitle(movieArray, 2); printMovies(movieArray);
System.out.println(" Movies sorted according to released year in descending are:"); sortByYear(movieArray, 2); printMovies(movieArray);
System.out.println(" Movies sorted according to Studio in descending are:"); sortByStudio(movieArray, 2); printMovies(movieArray); }
}
Instructions: Using a list of movies you own or wish to see, sort them based on title, year created, or movie studio. Use the selection sort algorithm to reorder the collection as requested in ascending or descending order. 1. Create a new project called 07.10 Assignment in your Module 07 assignments folder. 2. Copy your Movie.java and tester file from the previous sorting project as a starting point. Rename the tester to v3. Delete the existing sort methods. 3. Declare an array of at least 10 Movie objects. For each, you will need the movie title, year, and studio. Of course, be sure to use school-appropriate movie titles. For example: Meet the Robinsons, 2007, Disney 4. Design a static method that traverses through the array and prints each element. 5. Create the following static methods in the tester class. Utilize the selection sort algorithm. Each method will take two arguments: the array and an int parameter. Sort appropriately depending on the value of the second parameter: 1 sort ascending, or 2 sort descending. a. a method that sorts the array by the movie title b. a method that sorts the array by year released c. a method that sorts the array by the name of the studio that produces it 6. Test your sorting methods by calling each and displaying the results. Start by showing the array without sorting. Then demonstrate sorting by title in both ascending and descending order. Do the same for year and studio. Be sure to clearly label your output so someone looking at it knows which sort was applied each time. 07.10 Selection Sort Grading Rubric Points Possible Points Earned Components Comments included for name, date, and purpose of the program. 1 Create a tester class with and array of Movie objects. 2 Create a method to print all the Movie objects in the array. 1 Create a selection sort method to sort the array by title. 3 Create a selection sort method to sort the array by years. 3 Create a selection sort method to sort the array by studio. 3 Sort methods invoked and run properly for ascending and descending order. 2 Output is clearly labeled, formatted, and accurate. 2 No compiler errors. No runtime errors. 2Step 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