Question

In: Computer Science

In Java... Create a class named _MyArrays which has a main( ) and other static methods....

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“

Solutions

Expert Solution

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:


Related Solutions

Java Programming Create a class named Problem1, and create a main method, the program does the...
Java Programming Create a class named Problem1, and create a main method, the program does the following: - Prompt the user to enter a String named str. - Prompt the user to enter a character named ch. - The program finds the index of the first occurrence of the character ch in str and print it in the format shown below. - If the character ch is found in more than one index in the String str, the program prints...
Question 3 A java source module contains the following class with the static methods main and...
Question 3 A java source module contains the following class with the static methods main and procedure1, and the instance method procedure2 (assume given the bodies of procedure1 and procedure2): public class TestQuestion3             {                         static int result, num1 = 10;                         public static void Main( String [ ] args )                         {                                     int [ ] list1 =   { 2, 4, 6, 8, 10}, list2;                                     .    .    .                         }                         static void procedure1( void )                         {                                     .   .   .                         } void procedure2( void )...
In java: -Create a class named Animal
In java: -Create a class named Animal
You shall implement six static methods in a class named BasicBioinformatics. Each of the methods will...
You shall implement six static methods in a class named BasicBioinformatics. Each of the methods will perform some analysis of data considered to be DNA. DNA shall be represented arrays of chars containing only the characters A, C, G and T. In addition to the six methods you will implement, six other methods exist in the class, which use Strings instead of char arrays to represent DNA. These other methods simply invoke the methods you are to implement, so all...
Java Create a class named Billing that includes three overloaded computeBill() methods for a photo book...
Java Create a class named Billing that includes three overloaded computeBill() methods for a photo book store. main() main() will ask the user for input and then call functions to do calculations. The calculations will be returned to main() where they will be printed out. First function Create a function named computeBill that receives on parameter. It receives the price of an item. It will then add 8.25% sales tax to this and return the total due back to main()....
Java Codes: 1. Create a class named Proficiency1Practice In the main method, first ask the user...
Java Codes: 1. Create a class named Proficiency1Practice In the main method, first ask the user to enter a short sentence which ends in a period. Use Java String class methods to determine the following about the sentence and display in the console: • How many total characters are in the sentence? • What is the first word of the sentence? Assume the words are separated by a space. • How many characters are in the first word of the...
CODE IN JAVA Create a new class named Task1. In its main function, use Scanner to...
CODE IN JAVA Create a new class named Task1. In its main function, use Scanner to read integers from the keyboard with the method nextInt. Use a try catch block to capture non-integer input, and tell the user, "This is not an Integer". The program loop should end when the user enters the string "quit". (Hint: "quit" is clearly not a number and will be captured in the try / catch block.) A typical Output Dialog is shown below: Enter...
In Java. Create a class called FileSumWrapper with a method that has the signature public static...
In Java. Create a class called FileSumWrapper with a method that has the signature public static void handle(String filename, int lowerBound) Make this method call FileSum.read and make your method catch all the errors. FileSum.read is a method that takes a filename and a lower bound, then sums up all the numbers in that file that are equal to or above the given lower bound. FileSum : import java.io.File; import java.rmi.UnexpectedException; import java.util.Scanner; public class FileSum { public static int...
Create a new Java file, containing this code public class DataStatsUser { public static void main...
Create a new Java file, containing this code public class DataStatsUser { public static void main (String[] args) { DataStats d = new DataStats(6); d.append(1.1); d.append(2.1); d.append(3.1); System.out.println("final so far is: " + d.mean()); d.append(4.1); d.append(5.1); d.append(6.1); System.out.println("final mean is: " + d.mean()); } } This code depends on a class called DataStats, with the following API: public class DataStats { public DataStats(int N) { } // set up an array (to accept up to N doubles) and other member...
java Objective: Create a class. Create objects. Use methods of a class. Create a class BankAccount...
java Objective: Create a class. Create objects. Use methods of a class. Create a class BankAccount to represent a bank account according to the following requirements: A bank account has three attributes: accountnumber, balance and customer name. Add a constructor without parameters. In the initialization of the attributes, set the number and the balance to zero and the customer name to an empty string. Add a constructor with three parameters to initialize all the attributes by specific values. Add a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT