Use Java please! Thank you. 1. Create a data set of 30 movies 2. Assign names to
ID: 3883708 • Letter: U
Question
Use Java please! Thank you.
1. Create a data set of 30 movies 2. Assign names to each of the 30 movies (you can use actual movie names, or Movie!, Movie2, Movie30) 3. Assign a random year to each of the movies (the range of the year would be 1920 to 2017), such that there is no more than one movie in a year 4. Assign a random running time to each of the movies (the range would be 60 to 200 minutes) 5. Assign a genre to each movie choosing from one of the following: Comedy, Drama, Sci-Fi, Action Sci-Fi, Documentary; make sure there are no more than 10 movies in any categor,y are no more than 10 movies in agr 6. Assign a random rating to each movie (range 0.1 to 10.0)Explanation / Answer
package name is movie
Tested on eclipse
/******************************Movie.java****************************/
package movie;
/**
* The Class Movie.
*/
public class Movie {
/** The movie name. */
private String movieName;
/** The released year. */
private Integer releasedYear;
/** The duration. */
private Integer duration;
/** The category. */
private String genre;
/** The rating. */
private Double rating;
/**
* Instantiates a new movie.
*
* @param movieName the movie name
* @param releasedYear the released year
* @param duration the duration
* @param genre the genre
* @param rating the rating
*/
public Movie(String movieName, Integer releasedYear, Integer duration, String genre, Double rating) {
super();
this.movieName = movieName;
this.releasedYear = releasedYear;
this.duration = duration;
this.genre = genre;
this.rating = rating;
}
/**
* Gets the movie name.
*
* @return the movieName
*/
public String getMovieName() {
return movieName;
}
/**
* Sets the movie name.
*
* @param movieName the movieName to set
*/
public void setMovieName(String movieName) {
this.movieName = movieName;
}
/**
* Gets the released year.
*
* @return the releasedYear
*/
public Integer getReleasedYear() {
return releasedYear;
}
/**
* Sets the released year.
*
* @param releasedYear the releasedYear to set
*/
public void setReleasedYear(Integer releasedYear) {
this.releasedYear = releasedYear;
}
/**
* Gets the duration.
*
* @return the duration
*/
public Integer getDuration() {
return duration;
}
/**
* Sets the duration.
*
* @param duration the duration to set
*/
public void setDuration(Integer duration) {
this.duration = duration;
}
/**
* Gets the genre.
*
* @return the genre
*/
public String getGenre() {
return genre;
}
/**
* Sets the genre.
*
* @param genre the genre to set
*/
public void setGenre(String genre) {
this.genre = genre;
}
/**
* Gets the rating.
*
* @return the rating
*/
public Double getRating() {
return rating;
}
/**
* Sets the rating.
*
* @param rating the rating to set
*/
public void setRating(Double rating) {
this.rating = rating;
}
}
/**************************************MovieDemo.java**********************************/
package movie;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
/**
* The Class MovieDemo.
*/
public class MovieDemo implements Comparator<Movie> {
/** The compare mode. */
private static int compare_mode;
/**
* The main method.
*
* @param args the arguments
*/
public static void main(String[] args) {
List<Movie> list = new ArrayList<>();
Movie movie1 = new Movie("Hera Pheri", 2000, 156, "Comedy", 8.2);
Movie movie2 = new Movie("Garam Masala", 2005, 146, "Comedy", 6.8);
Movie movie3 = new Movie("Coolie No. i", 1995, 143, "Comedy", 6.1);
Movie movie4 = new Movie("Dhamaal", 2007, 136, "Comedy", 7.1);
Movie movie5 = new Movie("Golmaal: Fun Unlimited", 2006, 150, "Comedy", 7.4);
Movie movie6 = new Movie("Hungama", 2003, 153, "Comedy", 7.5);
Movie movie7 = new Movie("Heyy Babyy", 2007, 144, "Comedy", 6.1);
Movie movie8 = new Movie("Chachi 420", 1997, 155, "Comedy", 7.4);
Movie movie9 = new Movie("Bheja Fry", 2007, 95, "Comedy", 7.7);
Movie movie10 = new Movie("Dulhe Raja", 1998, 143, "Comedy", 6.6);
Movie movie11 = new Movie("Qayamat: City Under Threat", 2003, 156, "Action", 4.7);
Movie movie12 = new Movie("Singham", 2011, 153, "Action", 6.7);
Movie movie13 = new Movie("Rowdy Rathor", 2012, 140, "Action", 5.8);
Movie movie14 = new Movie("Wanted ", 2009, 185, "Action", 6.3);
Movie movie15 = new Movie("Dhoom 2", 2006, 152, "Action", 6.4);
Movie movie16 = new Movie("Ek Tha Tiger", 2012, 132, "Action", 5.4);
Movie movie17 = new Movie("Race 2 ", 2013, 150, "Action", 5.2);
Movie movie18 = new Movie("Jung", 1996, 146, "Action", 4.0);
Movie movie19 = new Movie("Dabangg", 2010, 126, "Action", 6.3);
Movie movie20 = new Movie("Vijaypath", 1994, 163, "Action", 4.9);
Movie movie21 = new Movie("Sachin", 2017, 54, "Documentry", 8.9);
Movie movie22 = new Movie("Junun", 2015, 153, "Documentry", 7.5);
Movie movie23 = new Movie("Life in a Day", 2011, 95, "Documentry", 7.7);
Movie movie24 = new Movie("Tawai: A voice from the forest", 2017, 101, "Documentry", 8.8);
Movie movie25 = new Movie("In Jackson Heights", 2015, 190, "Documentry", 7.2);
Movie movie26 = new Movie("The Attacks of 26/11", 2013, 116, "Documentry", 6.8);
Movie movie27 = new Movie("India's Daughter", 2015, 63, "Documentry", 8.2);
Movie movie28 = new Movie("Love in India", 2009, 91, "Documentry", 6.6);
Movie movie29 = new Movie("David Wants to Fly", 2010, 96, "Documentry", 6.9);
Movie movie30 = new Movie("Tashi and the Monk", 2014, 39, "Documentry", 8.1);
list.add(movie1);
list.add(movie2);
list.add(movie3);
list.add(movie4);
list.add(movie5);
list.add(movie6);
list.add(movie7);
list.add(movie8);
list.add(movie9);
list.add(movie10);
list.add(movie11);
list.add(movie12);
list.add(movie13);
list.add(movie14);
list.add(movie15);
list.add(movie16);
list.add(movie17);
list.add(movie18);
list.add(movie19);
list.add(movie20);
list.add(movie21);
list.add(movie22);
list.add(movie23);
list.add(movie24);
list.add(movie25);
list.add(movie26);
list.add(movie27);
list.add(movie28);
list.add(movie29);
list.add(movie30);
Collections.sort(list, new MovieDemo());
Iterator<Movie> iterator = list.iterator();
System.out.println("******************Sorted based on Released Year******************");
compare_mode = 2;
printList(list);
System.out.println("******************Sorted based on Running Time******************");
compare_mode = 1;
Collections.sort(list, new MovieDemo());
printList(list);
}
@Override
public int compare(Movie o1, Movie o2) {
if (compare_mode == 1) {
return o1.getDuration().compareTo(o2.getDuration());
} else {
return o1.getReleasedYear().compareTo(o2.getReleasedYear());
}
}
/**
* Prints the list.
*
* @param list the list
*/
public static void printList(List<Movie> list) {
Iterator<Movie> iterator = list.iterator();
System.out.println(
String.format("%-50s %-20s %-15s %-20s %-15s", "Movie Name", "Year", "Duration", "Genre", "Rating"));
while (iterator.hasNext()) {
Movie movie = iterator.next();
String line = String.format("%-50s %-20s %-15s %-20s %-15s", movie.getMovieName(), movie.getReleasedYear(),
movie.getDuration(), movie.getGenre(), movie.getRating());
System.out.println(line);
}
}
}
/*******************************output*******************************/
******************Sorted based on Released Year******************
Movie Name Year Duration Genre Rating
Vijaypath 1994 163 Action 4.9
Coolie No. i 1995 143 Comedy 6.1
Jung 1996 146 Action 4.0
Chachi 420 1997 155 Comedy 7.4
Dulhe Raja 1998 143 Comedy 6.6
Hera Pheri 2000 156 Comedy 8.2
Hungama 2003 153 Comedy 7.5
Qayamat: City Under Threat 2003 156 Action 4.7
Garam Masala 2005 146 Comedy 6.8
Golmaal: Fun Unlimited 2006 150 Comedy 7.4
Dhoom 2 2006 152 Action 6.4
Dhamaal 2007 136 Comedy 7.1
Heyy Babyy 2007 144 Comedy 6.1
Bheja Fry 2007 95 Comedy 7.7
Wanted 2009 185 Action 6.3
Love in India 2009 91 Documentry 6.6
Dabangg 2010 126 Action 6.3
David Wants to Fly 2010 96 Documentry 6.9
Singham 2011 153 Action 6.7
Life in a Day 2011 95 Documentry 7.7
Rowdy Rathor 2012 140 Action 5.8
Ek Tha Tiger 2012 132 Action 5.4
Race 2 2013 150 Action 5.2
The Attacks of 26/11 2013 116 Documentry 6.8
Tashi and the Monk 2014 39 Documentry 8.1
Junun 2015 153 Documentry 7.5
In Jackson Heights 2015 190 Documentry 7.2
India's Daughter 2015 63 Documentry 8.2
Sachin 2017 54 Documentry 8.9
Tawai: A voice from the forest 2017 101 Documentry 8.8
******************Sorted based on Running Time******************
Movie Name Year Duration Genre Rating
Tashi and the Monk 2014 39 Documentry 8.1
Sachin 2017 54 Documentry 8.9
India's Daughter 2015 63 Documentry 8.2
Love in India 2009 91 Documentry 6.6
Bheja Fry 2007 95 Comedy 7.7
Life in a Day 2011 95 Documentry 7.7
David Wants to Fly 2010 96 Documentry 6.9
Tawai: A voice from the forest 2017 101 Documentry 8.8
The Attacks of 26/11 2013 116 Documentry 6.8
Dabangg 2010 126 Action 6.3
Ek Tha Tiger 2012 132 Action 5.4
Dhamaal 2007 136 Comedy 7.1
Rowdy Rathor 2012 140 Action 5.8
Coolie No. i 1995 143 Comedy 6.1
Dulhe Raja 1998 143 Comedy 6.6
Heyy Babyy 2007 144 Comedy 6.1
Jung 1996 146 Action 4.0
Garam Masala 2005 146 Comedy 6.8
Golmaal: Fun Unlimited 2006 150 Comedy 7.4
Race 2 2013 150 Action 5.2
Dhoom 2 2006 152 Action 6.4
Hungama 2003 153 Comedy 7.5
Singham 2011 153 Action 6.7
Junun 2015 153 Documentry 7.5
Chachi 420 1997 155 Comedy 7.4
Hera Pheri 2000 156 Comedy 8.2
Qayamat: City Under Threat 2003 156 Action 4.7
Vijaypath 1994 163 Action 4.9
Wanted 2009 185 Action 6.3
In Jackson Heights 2015 190 Documentry 7.2
Thanks a lot. Please let me know if you have any doubt.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.