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 attires to stock and adjustment grounds (10 points)

    2. Right at lowest individual attire of objects (10 points)

    3. Right sorting to adjust grounds (10 points)

    4. Right processs to do disconnected and repetitive is-sue. The deep process should not attributable attributable attributable attributable attributable attributable own over than 20 lines of decree (10 points)

    5. Implement the plan suitably (50 points)

    10 points gain be awarded ce right of meaningful identifiers, harmonious smoothness, explanatory comments in your decree and properly cematted output, including defend shots of action.

    B. Description

    Netflix provides an online video streaming utility. Rightrs can browse and pick-out videos fixed on their preference; titles can as-well be reserved fixed on ratings and other attributes. Ce this plan, we impersonate a movie streaming utility common to Netflix, still on a plenteous smaller layer. Each movie has the cethcoming attributes: Spectry, year, ordinary spell (minutes), genre, rating (on a layer of 10). The cethcoming needs to be dindividual as sunder of the plan:

    1. Make a grounds cemal of 30 movies

    2. Assign spectrys to each of the 30 movies (you can right real movie spectrys, or Movie1, Movie2, …, Movie30)

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

    4. Assign a vague ordinary spell to each of the movies (the rove 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; construct certain there are no over than 10 movies in any category

    6. Assign a vague rating to each movie (rove 0.1 to 10.0)

    Right a disconnected adjust to make the movie objects. Perfect the movie objects must be stockd using an attire. You can right joined attires as needful. The sorting decree must be moderate as sunder of the plan. Make a menu fixed program with the cethcoming discretions:

    1. Catalogue perfect the movies

    2. Vault the movies reserved according to year, starting with the oldest individual

    3. Sort the movies according to ordinary spell, starting with the shortest

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

    5. Petition rightr ce a genre, and vault perfect the movies obligatory to that restricted genre

    6. Search ce a restricted movie by spectry, and vault perfect the details if the movies exists

    7. Supplement a movie to the catalogue of movies (petition the rightr ce perfect the details)

    8. Exit The program continues to complete until the rightr selects discretion to “Exit”. The rightr is perfectowed to supplement a culmination of 5 movies.

    Expert Response

     

    Decree to copy:

    import java.util.Random;

    import java.util.Scanner;

    class Movie

    {

    String spectry,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 Spectry = “+name);

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

    System.out.println(“nOrdinary spell = “+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 adjust ordeal.

    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 vault: “);

    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 build”);

    }

    }

     

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

    {

     

    String spectry;

    Scanner sc=new Scanner(System.in);

     

    System.out.print(“nEnter a spectry 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 build.”);

    m[i].ShowDetails();

    }

    }

    if(flag==0)

    {

    System.out.println(“nMovie not attributable attributable attributable attributable attributable attributable build.”);

    }

     

    }

     

    public static int max=0;

     

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

    {

    String spectry,genre;

    int year,time;

    float rating;

     

    if(max==5)

    {

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

    ” entered 5 movies.”);

    return;

    }

    Scanner sc=new Scanner(System.in);

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

    name=sc.nextLine();

     

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

    year=sc.nextInt();

     

    System.out.println(“nEnter the ordinary spell: “);

    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, spell, genre, rating);

    max=max+1;

     

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

    }

     

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

    {

    Vague rand=new Random();

     

    int year, spell;

    float rating;

    String spectry,genre;

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

    “Action”, “Documentary”};

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

    {

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

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

    rating = rand.nextFloat()*10;

    spectry = “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 perfect the movies.”);

    System.out.println

    (“2. Vault the movies reserved according to year.”);

    System.out.println

    (“3. Sort the movies according to ordinary spell.”);

    System.out.println

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

    System.out.println

    (“5. Vault perfect the movies obligatory”

    +” to a restricted genre”);

    System.out.println

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

    System.out.println

    (“7. Supplement 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 deep() process.

    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 dainty : “);

    choice=input.nextInt();

    operate(m, magnitude, dainty);

    }

    }

    }

    Sample output:

    Mini Netflix

    1. Catalogue perfect the movies.

    2. Vault the movies reserved according to year.

    3. Sort the movies according to ordinary spell.

    4. Sort the movies according to ratings.

    5. Vault perfect the movies obligatory to a restricted genre

    6. Search ce a restricted movie by spectry.

    7. Supplement a movie to the catalogue of movies.

    8. Exit The program.

    Enter your dainty : 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 perfect the movies.

    2. Vault the movies reserved according to year.

    3. Sort the movies according to ordinary spell.

    4. Sort the movies according to ratings.

    5. Vault perfect the movies obligatory to a restricted genre

    6. Search ce a restricted movie by spectry.

    7. Supplement a movie to the catalogue of movies.

    8. Exit The program.

    Enter your dainty : 6

    Enter a spectry to search: movie6

    Movie build.

    Movie Spectry = movie6

    Year = 1932

    Ordinary spell = 141

    Genre = Comedy

    Rating = 4.5804424

    Mini Netflix

    1. Catalogue perfect the movies.

    2. Vault the movies reserved according to year.

    3. Sort the movies according to ordinary spell.

    4. Sort the movies according to ratings.

    5. Vault perfect the movies obligatory to a restricted genre

    6. Search ce a restricted movie by spectry.

    7. Supplement a movie to the catalogue of movies.

    8. Exit The program.

    Enter your dainty : 5

    Enter a genre to vault: Comedy

    movie1

    movie6

    movie11

    movie16

    movie21

    movie26

    Mini Netflix

    1. Catalogue perfect the movies.

    2. Vault the movies reserved according to year.

    3. Sort the movies according to ordinary spell.

    4. Sort the movies according to ratings.

    5. Vault perfect the movies obligatory to a restricted genre

    6. Search ce a restricted movie by spectry.

    7. Supplement a movie to the catalogue of movies.

    8. Exit The program.

    Enter your dainty : 8

    Exiting…