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 stock and parcelment grounds (10 points)

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

    3. Truth sorting to parcel grounds (10 points)

    4. Truth manners to do disconnected and repetitive effect. The main manner should referable enjoy past than 20 lines of regulation (10 points)

    5. Implement the design well (50 points)

    10 points gain be awarded control truth of meaningful identifiers, agreeing indentation, explanatory comments in your regulation and justly controlmatted output, including cloak shots of attempt.

    B. Description

    Netflix provides an online video streaming utility. Truthrs can browse and appropriate videos established on their preference; titles can besides be nice established on ratings and other attributes. Control this design, we impersonate a movie streaming utility common to Netflix, excepting on a considerable smaller flake. Each movie has the subjoined attributes: Indicate, year, present occasion (minutes), genre, rating (on a flake of 10). The subjoined needs to be dindividual as deal-out of the design:

    1. Invent a grounds regular of 30 movies

    2. Assign indicates to each of the 30 movies (you can truth objective movie indicates, or Movie1, Movie2, …, Movie30)

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

    4. Assign a vague present occasion to each of the movies (the place would be 60 to 200 minutes)

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

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

    Truth a disconnected dispose to invent the movie objects. Every the movie objects must be stockd using an decorate. You can truth subjoined decorates as essential. The sorting regulation must be interjacent as deal-out of the design. Invent a menu established program with the subjoined discretions:

    1. Inventory every the movies

    2. Flaunt the movies nice according to year, starting with the oldest individual

    3. Sort the movies according to present occasion, starting with the shortest

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

    5. Ask truthr control a genre, and flaunt every the movies connected to that unfair genre

    6. Search control a unfair movie by indicate, and flaunt every the details if the movies exists

    7. Supplement a movie to the inventory of movies (ask the truthr control every the details)

    8. Exit The program continues to consummate until the truthr selects discretion to “Exit”. The truthr is everyowed to supplement a ultimatum of 5 movies.

    Expert Tally

     

    Regulation to copy:

    import java.util.Random;

    import java.util.Scanner;

    class Movie

    {

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

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

    System.out.println(“nPresent occasion = “+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 cupel.

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

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

    }

    }

     

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

    {

     

    String indicate;

    Scanner sc=new Scanner(System.in);

     

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

    m[i].ShowDetails();

    }

    }

    if(flag==0)

    {

    System.out.println(“nMovie referable root.”);

    }

     

    }

     

    public static int max=0;

     

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

    {

    String indicate,genre;

    int year,time;

    float rating;

     

    if(max==5)

    {

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

    ” entered 5 movies.”);

    return;

    }

    Scanner sc=new Scanner(System.in);

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

    name=sc.nextLine();

     

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

    year=sc.nextInt();

     

    System.out.println(“nEnter the present occasion: “);

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

    max=max+1;

     

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

    }

     

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

    {

    Vague rand=new Random();

     

    int year, occasion;

    float rating;

    String indicate,genre;

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

    “Action”, “Documentary”};

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

    {

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

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

    rating = rand.nextFloat()*10;

    indicate = “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. Inventory every the movies.”);

    System.out.println

    (“2. Flaunt the movies nice according to year.”);

    System.out.println

    (“3. Sort the movies according to present occasion.”);

    System.out.println

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

    System.out.println

    (“5. Flaunt every the movies connected”

    +” to a unfair genre”);

    System.out.println

    (“6. Search control a unfair movie by indicate.”);

    System.out.println

    (“7. Supplement a movie to the inventory 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 main() manner.

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

    choice=input.nextInt();

    operate(m, extent, select);

    }

    }

    }

    Sample output:

    Mini Netflix

    1. Inventory every the movies.

    2. Flaunt the movies nice according to year.

    3. Sort the movies according to present occasion.

    4. Sort the movies according to ratings.

    5. Flaunt every the movies connected to a unfair genre

    6. Search control a unfair movie by indicate.

    7. Supplement a movie to the inventory of movies.

    8. Exit The program.

    Enter your select : 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. Inventory every the movies.

    2. Flaunt the movies nice according to year.

    3. Sort the movies according to present occasion.

    4. Sort the movies according to ratings.

    5. Flaunt every the movies connected to a unfair genre

    6. Search control a unfair movie by indicate.

    7. Supplement a movie to the inventory of movies.

    8. Exit The program.

    Enter your select : 6

    Enter a indicate to search: movie6

    Movie root.

    Movie Indicate = movie6

    Year = 1932

    Present occasion = 141

    Genre = Comedy

    Rating = 4.5804424

    Mini Netflix

    1. Inventory every the movies.

    2. Flaunt the movies nice according to year.

    3. Sort the movies according to present occasion.

    4. Sort the movies according to ratings.

    5. Flaunt every the movies connected to a unfair genre

    6. Search control a unfair movie by indicate.

    7. Supplement a movie to the inventory of movies.

    8. Exit The program.

    Enter your select : 5

    Enter a genre to flaunt: Comedy

    movie1

    movie6

    movie11

    movie16

    movie21

    movie26

    Mini Netflix

    1. Inventory every the movies.

    2. Flaunt the movies nice according to year.

    3. Sort the movies according to present occasion.

    4. Sort the movies according to ratings.

    5. Flaunt every the movies connected to a unfair genre

    6. Search control a unfair movie by indicate.

    7. Supplement a movie to the inventory of movies.

    8. Exit The program.

    Enter your select : 8

    Exiting…