CS102 Tutorial 2

Complete the following exercises pasted below. For each exercise, give an algorithm/java code.



Q1. Write a program that calculates the total score for students in a class. Suppose the scores are stored in a 2-dimensional array named scores. The rows in scores refers to a student. The column refers to the earned score in an exam (between 0 and 10). The user provides the number of students, and the number of exams. Your program randomly fills the values in the 2D array. Your program shows the sum of scores for each student.
//Q1
        public class EXArray2D1 {
            public static void main(String [] s)
            {
                //TO DO: Ask the user to input number of students and number of exams
                
                
                //Define array
                //int [][] a = new int [rows][cols];
                
                
                //Randomly fill the array
                
                
                //Display the sum for each student
                
                
        
        
                
            }
            
        }
        


Q2. Write a program that finds the nearest Uber ride. Read a text file that gives the x,y coordinates of each Uber ride on a 2D plane. Store this information in a 2D array. Ask the user to enter his current location (x,y). Find the Uber ride closest to you! Hint: distance = Math.hypot(x2 - x1, y2 - y1); (x1,y1) and (x2,y2) are two points in a 2D plane.
//Q2
        public class EXArray2D2 {
            public static void main(String [] s)
            {
                //TO DO: Make a 2D array of type double
                
                //Open the file "E2.txt" and read the contents in the array
                
                //Ask user to input his current x,y coordinates.
                
                //For each row in the array, call the computeDistance method
                
                //Find the shortest distance and display the ride #
                
                
            }
            
            public static double computeDistance(double x1, double y1,double x2, double y2)
            {
                //use the formula
                return 0;
            }
        }

        


Q3. Write a program that grades the scores of a multiple choice exam. There are 10 questions in the exam. The possible answer for each question is A, B, C, D. Ask the user to type 10 characters. Each character must be A, B, C or D. This is the correct answer KEY. Read a text file "E3.txt" that gives the answers for students. Show the total score for each student. Also show the average score, highest and the lowest scores.
//Q3
        public class EXArray2D3 {
            public static void main(String [] s)
            {
                //TO DO: Make a 2D array of type char
                char [][] Scores;
                
                //Ask user to input the correct answer and store it in KEY.
                char [] KEY = new char [10];
                
                //Open the file "E3.txt" and read the contents in the array
                
                //call getScore method. Compute the score for each row in Scores.
        
                //display the average, max and min scores.
                
            }
            
            
            public static int getScore(char [][] C, char [] KEY, int row)
            {
                //grade the score for the student in row
                
                //match each column value in C[row][col] with KEY[col]. If it is
                //identical, student eachs 1 pt.
                
                //return the sum
                return 0;
            }    
            
            
        }