CS102 Tutorial 2
Complete the following exercises pasted below. For each exercise, give an algorithm/java code.
//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
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
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;
}
}