In: Computer Science
In Java...
Create a class named _MyArrays which has a main( ) and other static methods.
Part I (30%) [Main method] In the main() - Request the number of reviewers (r) and movies (m) - Declare a r x m two-dimensional array of integers - Allow the user to enter distinct values , row by row to fill the two dimensional array - Display the two-dimensional array using a _displayArray method. - Using the _printHighestLowestMovieRating method print the highest and lowest rating for each movie. - Using the _printAverageReviewerRating method print the average reviewer rating for each reviewer. - Test your program with the information in the example on the first page.
Part II (20%) [_displayArray] The _displayArray method must have the following specifications and functionality: o Only Takes the two-dimensional array as a formal parameter/argument o Displays the array data as a matrix (i.e. Rows and Columns) ( you know how to find the row and column without (r ) and (m) ) o Does not return any value.
Part III (20%) [_printHighestLowestReviewerRating] The _ printHighestLowestReviewerRating method must have the following specification and functionality: o Takes the two-dimensional array as a formal parameter/argument as well as r and m o Displays each reviewer code and the highest and lowest rating. o Sample output “Highest rating for review # 1 is 6 and Lowest is 2”
Part IV (20%) [_ printAverageMovieRating] The _ printAverageMovieRating method must have the following specification and functionality: o Takes the two-dimensional array as a formal parameter/argument as well as r and m o Displays each Movie code and the average Movie rating. o Sample output : “ The average rating of the movie #4 is 6.67“
import java.util.Scanner;
class Main {
static void displayArray(int review[][]){
System.out.println("All review entries are:");
for(int i=0;i<review.length;i++){
for(int j=0;j<review[i].length;j++){
System.out.print(review[i][j]+" ");
}
System.out.println();
}
}
static void printAverageMovieRating(int review[][],int r,int m){
for(int i=0;i<m;i++){
double total=0;
for(int j=0;j<r;j++){
total = total + review[j][i];
}
System.out.println("The average rating of movie #"+(i+1)+" is "+String.format("%.2f",(total/r)));
}
}
static void printHighestLowestReviewerRating(int review[][],int r,int m){
System.out.println("---Highest and Lowest ratings:----");
System.out.println(" Highest Lowest");
for(int i=0;i<m;i++){
int low =100;
int high= -1;
for(int j=0;j<r;j++){
if(review[j][i]<low)
low = review[j][i];
if(review[j][i]>high)
high = review[j][i];
}
System.out.println("Movie #"+(i+1)+" "+high+" "+low);
}
}
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
System.out.println("Enter #reviewers(r):");
int r = sc.nextInt();
System.out.println("Enter #movies(m):");
int m = sc.nextInt();
int review[][] = new int[r][m];
System.out.println("Enter "+r+"×"+m+" entries row wise:");
for(int i=0;i<r;i++){
for(int j=0;j<m;j++){
review[i][j] = sc.nextInt();
}
}
//display review matrix entries
displayArray(review);
//display highest and Lowest rating of each movies
printHighestLowestReviewerRating(review, r, m);
//display average rating of each movie
printAverageMovieRating(review,r,m);
sc.close();
}
}
Sample Output for the above code is as following: