Arrays and Loops – 50 course points
The purpose of this assignment is for you to practice one and two dimensional arrays.
Refer to our Programming Assignments FAQ for instructions on how to install VSCode, how to use the command line and how to submit your assignments.
Programming
Write 2 programs and submit on Autolab.
We provide this zip file containing FindDuplicate.java, and RURottenTomatoes.java. For each problem, update and submit the corresponding file.
Observe the following rules:
- DO NOT use System.exit()
- DO NOT add any import statements
- DO NOT add the project or package statements
- DO NOT change the class name
- DO NOT change the headers of ANY of the given methods
- DO NOT add any new class fields
- ONLY print the result as specified by the example for each problem.
- DO NOT print other messages, follow the examples for each problem.
- Find a duplicate (20 points). Write a program FindDuplicate.java that reads n integer arguments from the command line into an integer array of length n, where each value is between is 1 and n, and displays true if there are any duplicate values, false otherwise.
java FindDuplicate 2 10 8 5 4 1 3 6 7 9
false
java FindDuplicate 4 5 2 1 2
true
- RU Rotten Tomatoes (30 points). Write a program RURottenTomatoes.java that creates a 2 dimensional integer array of movie ratings from the command line arguments and displays the index of the movie that has the highest sum of ratings. Ratings range from 1 to 5 (inclusive). The rows of the 2D array correspond to movie reviewers and the columns of the 2D array correspond to movies. The reviewer at index 2 gave movie at index 0 a rating of 4. Take a look at the following example for an explanation on the command line arguments sequence.
-
- The first argument corresponds to the number of reviewers and the second argument corresponds to the number of movies (the dimensions of the 2D integer array). Following are the movie ratings in a row-major order. This means that the first row is filled first, then the second row, etc.
- In the example above there are 3 reviewers and 2 movies, and the program displays 0 (zero) because the movie at index zero has the highest sum of ratings (movie 0 has sum of ratings equals to 12 while move 1 has sum of ratings equals to 6).
- Note 1: assume that the order of the first two input arguments are the number of rows and the number of columns.
- Note 2: assume that there are enough arguments to completely fill the 2D array.
- Note 3: if multiple movies have the same highest sum of ratings, display the movie with the lowest index.
Before submission
- Collaboration policy. Read our collaboration policy here.
- Update @author. Update the @author tag of the files with your name, email and netid.
- Submitting the assignment. Submit FindDuplicate.java, and RURottenTomatoes.java separately via the web submission system called Autolab. To do this, click the Assignments link from the course website; click the Submit link for that assignment.
Getting help
If anything is unclear, don’t hesitate to drop by office hours or post a question on Piazza. Find instructors office hours by clicking the Staff link from the course website. In addition to office hours we have the CAVE (Collaborative Academic Versatile Environment), a community space staffed with lab assistants which are undergraduate students further along the CS major to answer questions.