Java Programming
A. Objectives
1. Using vests to treasury and rule grounds (10 points)
2. Explanation at lowest single vest of objects (10 points)
3. Explanation sorting to order grounds (10 points)
4. Explanation modes to do disconnected and repetitive performance. The deep mode should referable bear past than 20 lines of decree (10 points)
5. Implement the purpose truly (50 points)
10 points succeed be awarded restraint explanation of meaningful identifiers, accordant dispersion, explanatory comments in your decree and correctly restraintmatted output, including harbor shots of action.
B. Description
Netflix provides an online video streaming benefit. Explanationrs can browse and elect videos domiciled on their preference; titles can as-well be arranged domiciled on ratings and other attributes. Restraint this purpose, we counterfeit a movie streaming benefit alike to Netflix, beside on a considerable smaller layer. Each movie has the subjoined attributes: Spectry, year, exoteric period (minutes), genre, rating (on a layer of 10). The subjoined needs to be dsingle as multiply of the purpose:
1. Fashion a grounds fixed of 30 movies
2. Assign spectrys to each of the 30 movies (you can explanation express movie spectrys, or Movie1, Movie2, …, Movie30)
3. Assign a aimless year to each of the movies (the rank of the year would be 1920 to 2017), such that there is no past than single movie in a year
4. Assign a aimless exoteric period to each of the movies (the rank would be 60 to 200 minutes)
5. Assign a genre to each movie choosing from single of the subjoined: Comedy, Drama, Sci-Fi, Action, Documentary; effect believing there are no past than 10 movies in any category
6. Assign a aimless rating to each movie (rank 0.1 to 10.0)
Explanation a disconnected adjust to fashion the movie objects. Perfect the movie objects must be treasuryd using an vest. You can explanation affixed vests as indispensable. The sorting decree must be included as multiply of the purpose. Fashion a menu domiciled program with the subjoined discretions:
1. Catalogue perfect the movies
2. Show the movies arranged according to year, starting with the oldest single
3. Sort the movies according to exoteric period, starting with the shortest
4. Sort the movies according to ratings, starting with the leading rating
5. Crave explanationr restraint a genre, and show perfect the movies appertaining to that restricted genre
6. Search restraint a restricted movie by spectry, and show perfect the details if the movies exists
7. Supplement a movie to the catalogue of movies (crave the explanationr restraint perfect the details)
8. Exit The program continues to complete until the explanationr selects discretion to “Exit”. The explanationr is perfectowed to supplement a culmination of 5 movies.
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(“nExoteric period = “+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 touchstone.
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 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 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 spectry,genre;
int year,time;
float rating;
if(max==5)
{
System.out.println(“nYou bear 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 exoteric period: “);
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, period, genre, rating);
max=max+1;
System.out.println(“nMovie Entered!”);
}
public static void SetRandom(Movie m[],int size)
{
Aimless rand=new Random();
int year, period;
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;
period = 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. Show the movies arranged according to year.”);
System.out.println
(“3. Sort the movies according to exoteric period.”);
System.out.println
(“4. Sort the movies according to ratings.”);
System.out.println
(“5. Show perfect the movies appertaining”
+” to a restricted genre”);
System.out.println
(“6. Search restraint 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() 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 exquisite : “);
choice=input.nextInt();
operate(m, extent, exquisite);
}
}
}
Sample output:
Mini Netflix
1. Catalogue perfect the movies.
2. Show the movies arranged according to year.
3. Sort the movies according to exoteric period.
4. Sort the movies according to ratings.
5. Show perfect the movies appertaining to a restricted genre
6. Search restraint a restricted movie by spectry.
7. Supplement a movie to the catalogue of movies.
8. Exit The program.
Enter your exquisite : 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. Show the movies arranged according to year.
3. Sort the movies according to exoteric period.
4. Sort the movies according to ratings.
5. Show perfect the movies appertaining to a restricted genre
6. Search restraint a restricted movie by spectry.
7. Supplement a movie to the catalogue of movies.
8. Exit The program.
Enter your exquisite : 6
Enter a spectry to search: movie6
Movie set-up.
Movie Spectry = movie6
Year = 1932
Exoteric period = 141
Genre = Comedy
Rating = 4.5804424
Mini Netflix
1. Catalogue perfect the movies.
2. Show the movies arranged according to year.
3. Sort the movies according to exoteric period.
4. Sort the movies according to ratings.
5. Show perfect the movies appertaining to a restricted genre
6. Search restraint a restricted movie by spectry.
7. Supplement a movie to the catalogue of movies.
8. Exit The program.
Enter your exquisite : 5
Enter a genre to show: Comedy
movie1
movie6
movie11
movie16
movie21
movie26
Mini Netflix
1. Catalogue perfect the movies.
2. Show the movies arranged according to year.
3. Sort the movies according to exoteric period.
4. Sort the movies according to ratings.
5. Show perfect the movies appertaining to a restricted genre
6. Search restraint a restricted movie by spectry.
7. Supplement a movie to the catalogue of movies.
8. Exit The program.
Enter your exquisite : 8
Exiting…