Homework Solution: 1. Using arrays to store and process data (10 points)…

    Java Programming A. Objectives 1. Using arrays to store and process data (10 points) 2. Use at least one array of objects (10 points) 3. Use sorting to arrange data (10 points) 4. Use methods to do separate and repetitive work. The main method should not have more than 20 lines of code (10 points) 5. Implement the project correctly (50 points) 10 points will be awarded for use of meaningful identifiers, consistent indentation, explanatory comments in your code and properly formatted output, including screen shots of execution. B. Description Netflix provides an online video streaming service. Users can browse and choose videos based on their preference; titles can also be sorted based on ratings and other attributes. For this project, we simulate a movie streaming service similar to Netflix, but on a much smaller scale. Each movie has the following attributes: Name, year, running time (minutes), genre, rating (on a scale of 10). The following needs to be done as part of the project: 1. Create a data set of 30 movies 2. Assign names to each of the 30 movies (you can use actual movie names, or Movie1, 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) Use a separate class to create the movie objects. All the movie objects must be stored using an array. You can use additional arrays as necessary. The sorting code must be included as part of the project. Create a menu based program with the following options: 1. List all the movies 2. Display the movies sorted according to year, starting with the oldest one 3. Sort the movies according to running time, starting with the shortest 4. Sort the movies according to ratings, starting with the highest rating 5. Ask user for a genre, and display all the movies belonging to that specific genre 6. Search for a specific movie by name, and display all the details if the movies exists 7. Add a movie to the list of movies (ask the user for all the details) 8. Exit The program continues to execute until the user selects option to “Exit”. The user is allowed to add a maximum of 5 movies.

    Expert Answer

     
    Code to copy: import java.util.Random; import java.util.Scanner;

    Java Programming

    A. Objectives

    1. Using decorates to abundance and way postulates (10 points)

    2. Interpretation at meanest individual decorate of objects (10 points)

    3. Interpretation sorting to dispose postulates (10 points)

    4. Interpretation modes to do disconnected and repetitive composition. The ocean mode should referable entertain over than 20 lines of sequence (10 points)

    5. Implement the contrivance justly (50 points)

    10 points obtain be awarded ce interpretation of meaningful identifiers, congruous cavity, explanatory comments in your sequence and uprightly cematted output, including mitigate shots of attempt.

    B. Description

    Netflix provides an online video streaming employment. Interpretationrs can browse and appropriate videos established on their preference; titles can as-well be select established on ratings and other attributes. Ce this contrivance, we counterfeit a movie streaming employment harmonious to Netflix, yet on a greatly smaller flake. Each movie has the cethcoming attributes: Call, year, prevalent season (minutes), genre, rating (on a flake of 10). The cethcoming needs to be dindividual as segregate of the contrivance:

    1. Originate a postulates established of 30 movies

    2. Assign calls to each of the 30 movies (you can interpretation explicit movie calls, or Movie1, Movie2, …, Movie30)

    3. Assign a purposeless year to each of the movies (the dispose of the year would be 1920 to 2017), such that there is no over than individual movie in a year

    4. Assign a purposeless prevalent season to each of the movies (the dispose would be 60 to 200 minutes)

    5. Assign a genre to each movie choosing from individual of the cethcoming: Comedy, Drama, Sci-Fi, Action, Documentary; effect stable there are no over than 10 movies in any category

    6. Assign a purposeless rating to each movie (dispose 0.1 to 10.0)

    Interpretation a disconnected dispose to originate the movie objects. Total the movie objects must be abundanced using an decorate. You can interpretation joined decorates as essential. The sorting sequence must be comprised as segregate of the contrivance. Originate a menu established program with the cethcoming discretions:

    1. Catalogue total the movies

    2. Show the movies select according to year, starting with the oldest individual

    3. Sort the movies according to prevalent season, starting with the shortest

    4. Sort the movies according to ratings, starting with the chief rating

    5. Request interpretationr ce a genre, and show total the movies cognate to that restricted genre

    6. Search ce a restricted movie by call, and show total the details if the movies exists

    7. Gather a movie to the catalogue of movies (request the interpretationr ce total the details)

    8. Exit The program continues to enact until the interpretationr selects discretion to “Exit”. The interpretationr is totalowed to gather a consummation of 5 movies.

    Expert Rejoinder

     

    Sequence to copy:

    import java.util.Random;

    import java.util.Scanner;

    class Movie

    {

    String call,genre;

    int year,time;

    float rating;

     

    public Movie ()

    {

    name=””;

    year=0;

    time=0;

    genre=””;

    rating=0;

    }

    public void SetDetails (String mname, int myear,

    int mtime, String mgenre, float mrating)

    {

    name=mname;

    year=myear;

    time=mtime;

    genre=mgenre;

    rating=mrating;

    }

     

    public void ShowDetails()

    {

    System.out.println(“nMovie Centire = “+name);

    System.out.println(“nYear = “+year);

    System.out.println(“nPrevalent season = “+time);

    System.out.println(“nGenre = “+genre);

    System.out.println(“nRating = “+rating);

    }

    public int GetYear()

    {

    return year;

    }

    public int GetTime()

    {

    return time;

    }

    public float GetRating()

    {

    return rating;

    }

    public String GetGenre()

    {

    return genre;

    }

    public String GetName()

    {

    return name;

    }

    public void SetYear(int myear)

    {

    year=myear;

    }

    public void SetTime(int mtime)

    {

    time=mtime;

    }

    public void SetRating(float mrating)

    {

    rating=mrating;

    }

    public void SetGenre(String mgenre)

    {

    genre=mgenre;

    }

    public void SetName(String mname)

    {

    name=mname;

    }

    }

    //Define the dispose proof.

    public class test

    {

    public static void Display(Movie m[],int size)

    {

    for(int i=0;i<size;i++)

    {

    System.out.println(m[i].GetName());

    }

    }

     

    public static void DisplayByYear(Movie m[],int size)

    {

    int min=0;

    for(int i=0;i<size;i++)

    {

    min=i;

    for(int j=0;j<size;j++)

    {

    if(m[j].GetYear() < m[min].GetYear())

    {

    min=j;

    }

    }

    System.out.println(m[min].GetName());

    }

    }

     

    public static void SortByTime(Movie m[],int size)

    {

    int min=0;

    for(int i=0;i<size;i++)

    {

    min=i;

    for(int j=0;j<size;j++)

    {

    if(m[j].GetYear() < m[min].GetYear())

    {

    min=j;

    }

    }

    Movie temp;

    temp=m[i];

    m[i]=m[min];

    m[min]=temp;

    }

    }

     

    public static void SortByRating(Movie m[],int size)

    {

    int min=0;

    for(int i=0;i<size;i++)

    {

    min=i;

    for(int j=0;j<size;j++)

    {

    if(m[j].GetYear() < m[min].GetYear())

    {

    min=j;

    }

    }

    Movie temp;

    temp=m[i];

    m[i]=m[min];

    m[min]=temp;

    }

    }

     

    public static void SearchByGenre(Movie m[], int size)

    {

    int flag=0;

    String genre;

    Scanner sc=new Scanner(System.in);

     

    System.out.print(“nEnter a genre to show: “);

    genre=sc.nextLine();

     

    for(int i=0;i<size;i++)

    {

    if(genre.equals(m[i].GetGenre()))

    {

    flag=1;

    System.out.println(m[i].GetName());

    }

    }

     

    if(flag==0)

    {

    System.out.println(“nNo movies set-up”);

    }

    }

     

    public static void SearchByName(Movie m[],int size)

    {

     

    String call;

    Scanner sc=new Scanner(System.in);

     

    System.out.print(“nEnter a centire to search: “);

    name=sc.nextLine();

     

    int flag=0;

    for(int i=0;i<size;i++)

    {

    if(name.equals(m[i].GetName()))

    {

    flag=1;

    System.out.println(“nMovie set-up.”);

    m[i].ShowDetails();

    }

    }

    if(flag==0)

    {

    System.out.println(“nMovie referable set-up.”);

    }

     

    }

     

    public static int max=0;

     

    public static void AddMovie(Movie m[], int size)

    {

    String call,genre;

    int year,time;

    float rating;

     

    if(max==5)

    {

    System.out.println(“nYou entertain already”+

    ” entered 5 movies.”);

    return;

    }

    Scanner sc=new Scanner(System.in);

    System.out.println(“nEnter the call: “);

    name=sc.nextLine();

     

    System.out.println(“nEnter the year: “);

    year=sc.nextInt();

     

    System.out.println(“nEnter the prevalent season: “);

    time=sc.nextInt();

     

    System.out.println(“nEnter the genre: “);

    genre=sc.nextLine();

     

    System.out.println(“nEnter the rating: “);

    rating=sc.nextFloat();

     

    m[size+max].SetDetails(name, year, season, genre, rating);

    max=max+1;

     

    System.out.println(“nMovie Entered!”);

    }

     

    public static void SetRandom(Movie m[],int size)

    {

    Purposeless rand=new Random();

     

    int year, season;

    float rating;

    String call,genre;

    String[] discretion={“Comedy”, “Drama”, “Sci-Fi”,

    “Action”, “Documentary”};

    for(int i=0;i<size;i++)

    {

    year = rand.nextInt((2017-1920)+1)+1920;

    season = rand.nextInt((200-60)+1)+60;

    rating = rand.nextFloat()*10;

    centire = “movie”+(i+1);

    genre = discretion[i%5];

     

    m[i].SetYear(year);

    m[i].SetTime(time);

    m[i].SetRating(rating);

    m[i].SetGenre(genre);

    m[i].SetName(name);

    }

    }

     

    public static void DisplayMenu()

    {

    System.out.println(“nMini Netflixn”);

    System.out.println(“1. Catalogue total the movies.”);

    System.out.println

    (“2. Show the movies select according to year.”);

    System.out.println

    (“3. Sort the movies according to prevalent season.”);

    System.out.println

    (“4. Sort the movies according to ratings.”);

    System.out.println

    (“5. Show total the movies cognate”

    +” to a restricted genre”);

    System.out.println

    (“6. Search ce a restricted movie by call.”);

    System.out.println

    (“7. Gather a movie to the catalogue of movies.”);

    System.out.println

    (“8. Exit The program.”);

    }

     

    public static void operate(Movie m[], int size, int choice)

    {

    switch(choice)

    {

    case 1:

    Display(m,size);

    break;

    case 2:

    DisplayByYear(m,size);

    break;

    case 3:

    SortByTime(m,size);

    break;

    case 4:

    SortByRating(m,size);

    break;

    case 5:

    SearchByGenre(m,size);

    break;

    case 6:

    SearchByName(m,size);

    break;

    case 7:

    AddMovie(m,size);

    break;

    case 8:

    System.out.println(“nExiting…”);

    System.exit(0);

    default:

    System.out.println(“nInvalid input!”);

    }

    }

    //Define the ocean() mode.

    public static void main(String[] args)

    {

    Movie m[]=new Movie[35];

    int size=30;

    int choice=0;

    for(int i=0;i<35;i++)

    {

    m[i]=new Movie();

    }

     

    SetRandom(m,size);

    Scanner input=new Scanner(System.in);

     

    while(choice!=8)

    {

    DisplayMenu();

     

    System.out.print(“nEnter your valuable : “);

    choice=input.nextInt();

    operate(m, magnitude, valuable);

    }

    }

    }

    Sample output:

    Mini Netflix

    1. Catalogue total the movies.

    2. Show the movies select according to year.

    3. Sort the movies according to prevalent season.

    4. Sort the movies according to ratings.

    5. Show total the movies cognate to a restricted genre

    6. Search ce a restricted movie by call.

    7. Gather a movie to the catalogue of movies.

    8. Exit The program.

    Enter your valuable : 1

    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

    Mini Netflix

    1. Catalogue total the movies.

    2. Show the movies select according to year.

    3. Sort the movies according to prevalent season.

    4. Sort the movies according to ratings.

    5. Show total the movies cognate to a restricted genre

    6. Search ce a restricted movie by call.

    7. Gather a movie to the catalogue of movies.

    8. Exit The program.

    Enter your valuable : 6

    Enter a centire to search: movie6

    Movie set-up.

    Movie Centire = movie6

    Year = 1932

    Prevalent season = 141

    Genre = Comedy

    Rating = 4.5804424

    Mini Netflix

    1. Catalogue total the movies.

    2. Show the movies select according to year.

    3. Sort the movies according to prevalent season.

    4. Sort the movies according to ratings.

    5. Show total the movies cognate to a restricted genre

    6. Search ce a restricted movie by call.

    7. Gather a movie to the catalogue of movies.

    8. Exit The program.

    Enter your valuable : 5

    Enter a genre to show: Comedy

    movie1

    movie6

    movie11

    movie16

    movie21

    movie26

    Mini Netflix

    1. Catalogue total the movies.

    2. Show the movies select according to year.

    3. Sort the movies according to prevalent season.

    4. Sort the movies according to ratings.

    5. Show total the movies cognate to a restricted genre

    6. Search ce a restricted movie by call.

    7. Gather a movie to the catalogue of movies.

    8. Exit The program.

    Enter your valuable : 8

    Exiting…