Use Java Please 1. Create a data set of 30 movies 2. Assign names to each of the
ID: 3889111 • Letter: U
Question
Use Java Please
1. Create a data set of 30 movies 2. Assign names to each of the 30 movies (you can use actual movie names, or Moviel, 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, Documentary; make sure there are no more than 10 movies in any category 6. Assign a random rating to each movie (range 0.1 to 10.0)Explanation / Answer
Movie.java
import java.util.ArrayList;
import java.util.Scanner;
public class Movie {
public static String[] movieNames = {"Movie1","Movie2","Movie3","Movie4","Movie5","Movie6",
"Movie7","Movie8","Movie9","Movie10","Movie11","Movie12",
"Movie13","Movie14","Movie15","Movie16","Movie17","Movie18",
"Movie19","Movie20","Movie21","Movie22","Movie23","Movie24",
"Movie25","Movie26","Movie27","Movie28","Movie29","Movie30"};
public static String[] years = {"1981","1982","1983","1984","1985","1986",
"1987","1988","1990","1970","1971","1972",
"1973","1974","1975","1976","1977","1978",
"1979","1980","1921","1922","1923","1924",
"1925","1926","1927","1928","1929","1930"};
public static String[] runningTimes = { "120","80","60","70","180","190",
"120","70","80","80","190","190",
"120","60","80","70","180","180",
"120","60","80","60","190","190",
"120","70","60","80","180","190"};
public static String[] genre = { "Documentary","Sci-Fi","Documentary","Drama","Sci-Fi","Drama",
"Drama","Documentary","Comedy","Sci-Fi","Documentary","Action",
"Action","Sci-Fi","Drama","Documentary","Action","Sci-Fi",
"Drama","Comedy","Drama","Sci-Fi","Comedy","Comedy",
"Action","Sci-Fi","Documentary","Action","Comedy","Sci-Fi"};
public static String[] rating = { "6.1","9.0","6.9","7.6","10.0","3.8",
"5.9","6.6","8.7","10.0","8.7","9.1",
"9.1","6.9","5.1","7.8","7.8","8.9",
"8.8","9.7","4.7","5.0","8.0","8.6",
"6.9","6.9","10.0","2.9","3.6","4.1"};
static Scanner scan = new Scanner(System.in);
public static void main(String [] args){
menu();
}
public static void menu(){
String choice = "";
while(!"E".equalsIgnoreCase(choice)){
System.out.println();
System.out.print("1.Display movies for a genre ");
System.out.print("2.Search by Movie name ");
System.out.print("3.Add Movie ");
System.out.print("E to Exit");
System.out.println();
choice= scan.nextLine();
if("1".equalsIgnoreCase(choice)){
//Asking the user
System.out.println("Enter genre: ");
String genreNew = scan.nextLine();
//Displaying all the movies in that genre
for(int i=0;i<movieNames.length;i++){
if(genreNew.equalsIgnoreCase(genre[i])){
System.out.println(movieNames[i]);
}
}
}
else if("2".equalsIgnoreCase(choice)){
//Asking the user
System.out.println("Enter movie name: ");
String movie = scan.nextLine();
//Displaying all the movie details
for(int i=0;i<movieNames.length;i++){
if(movie.equalsIgnoreCase(movieNames[i])){
System.out.println("Name: "+movieNames[i]+" Genre : "+genre[i]+" Year: "+years[i]+" Time : "+runningTimes[i]+
" Rating : "+rating[i]);
}
}
}
else if("3".equalsIgnoreCase(choice)){
//Asking the user
System.out.println("Enter movie name: ");
String movie = scan.nextLine();
System.out.println("Genre: ");
String genreg = scan.nextLine();
System.out.println("Year: ");
String year = scan.nextLine();
System.out.println("Running time: ");
String time = scan.nextLine();
System.out.println("Rating time: ");
String ratin = scan.nextLine();
String[] Marray = new String[movieNames.length+1];
String[] Garray = new String[movieNames.length+1];
String[] Yarray = new String[movieNames.length+1];
String[] Rnarray = new String[movieNames.length+1];
String[] Rtarray = new String[movieNames.length+1];
for(int i=0;i<movieNames.length;i++){
Marray[i] = movieNames[i];
Garray[i] = genre[i];
Yarray[i] = years[i];
Rnarray[i] = runningTimes[i];
Rtarray[i] = rating[i];
}
Marray[movieNames.length] = movie;
Garray[movieNames.length] = genreg;
Yarray[movieNames.length] = year;
Rnarray[movieNames.length] = time;
Rtarray[movieNames.length] = ratin;
movieNames = Marray;
genre = Garray;
years = Yarray;
runningTimes = Rnarray;
rating = Rtarray;
}
}
}
}
Sample output:
1.Display movies for a genre 2.Search by Movie name 3.Add Movie E to Exit
1
Enter genre:
Drama
Movie4
Movie6
Movie7
Movie15
Movie19
Movie21
1.Display movies for a genre 2.Search by Movie name 3.Add Movie E to Exit
Movie1
1.Display movies for a genre 2.Search by Movie name 3.Add Movie E to Exit
2
Enter movie name:
Movie1
Name: Movie1 Genre : Documentary Year: 1981 Time : 120 Rating : 6.1
1.Display movies for a genre 2.Search by Movie name 3.Add Movie E to Exit
3
Enter movie name:
Movie31
Genre:
Action
Year:
1989
Running time:
190
Rating time:
6.7
1.Display movies for a genre 2.Search by Movie name 3.Add Movie E to Exit
2
Enter movie name:
Movie31
Name: Movie31 Genre : Action Year: 1989 Time : 190 Rating : 6.7
1.Display movies for a genre 2.Search by Movie name 3.Add Movie E to Exit
E
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.