Question

In: Computer Science

Write a method that, given an array of grades stored as double values, computes and return...

Write a method that, given an array of grades stored as double values, computes and return their mean.
   Write another method that will return an array of the mean grade obtained by an arbitrary number of student.
   This method will take a 2-dimensional array of double values in which each row corresponds to the grade vector
   for a different student. You can compute the mean for each row as you did before...
   Once you are done, be [good] lazy and just reuse your previous method.

   If you are looking for yet another practice opportunity, what about a method that, given the whole matrix,
   would bump up a specific grade of a specific student by a given number of points?
   Signature of this method is not provided below.

*/
public class TinkeringWithArraysLive {
   public static void main(String[] args){
double[] s1 = {90.1, 80.2, 70.3, 30.4, 99.5};
System.out.println("Computing average of grades " + Arrays.toString(s1) + " result is " + mean(s1));

double[][] all = { {50.0, 60.0, 52.0, 58.0, 55.0},
   {60.0, 70.0, 62.0, 68.0, 65.0},
   {70.0, 80.0, 72.0, 78.0, 75.0}
   };
  
System.out.println("Averages for all students are " + Arrays.toString(mean(all)));
   } // end main
  
   public static double mean(double[] grades){
return 0.0;
   }// end method mean for vector of grades
  
   public static double[] mean(double[][] grades){
double[] result = new double[grades.length];
return result;
   }// end method mean for matrix of grades
} // end class

Solutions

Expert Solution

Code:

import java.util.Arrays;

public class TinkeringWithArraysLive {
public static void main(String[] args)
{
   double[] s1 = {90.1, 80.2, 70.3, 30.4, 99.5};
   System.out.println("Computing average of grades " + Arrays.toString(s1) + " result is " + mean(s1));

   double[][] all = { {50.0, 60.0, 52.0, 58.0, 55.0},
   {60.0, 70.0, 62.0, 68.0, 65.0},
   {70.0, 80.0, 72.0, 78.0, 75.0}
   };
  
   System.out.println("Averages for all students are " + Arrays.toString(mean(all)));
} // end main
  
public static double mean(double[] grades)
{
   double total = 0.0;   
   for(int i = 0;i < grades.length;i++)
   {
       total += grades[i];
   }
   return total/grades.length;
}// end method mean for vector of grades
  
public static double[] mean(double[][] grades)
{
   double[] result = new double[grades.length];
   for(int j = 0;j < grades.length;j++)
   {
       double total = 0.0;
       for(int i = 0;i < grades[j].length;i++)
       {
           total += grades[j][i];
       }
       result[j] = total/grades[j].length;
   }
  
  
   return result;
}// end method mean for matrix of grades
} // end class

OUTPUT:


Related Solutions

Write a method with the following header to return an array of integer values which are...
Write a method with the following header to return an array of integer values which are the largest values from each row of a 2D array of integer values public static int[] largestValues(int[][] num) For example, if the 2D array passed to the method is: 8 5 5 6 6 3 6 5 4 5 2 5 4 5 2 8 8 5 1 6 The method returns an array of integers which are the largest values from each row...
Write a function that will take in an array (of type double), and will return the...
Write a function that will take in an array (of type double), and will return the array with all of the elements doubled. You must use pass-by-reference and addressing and/or pointers to accomplish this task. C++
Write a function in C# that takes an array of double as the parameter, and return...
Write a function in C# that takes an array of double as the parameter, and return the average
Write a class DataSet that stores a number of values of type double in an array...
Write a class DataSet that stores a number of values of type double in an array list. Provide methods to insert a value to the array list and to compute the sum, average, and maximum value. Please put a note on what you did is for what. So I can understand this question better. Code provided: import java.util.*; public class DataSet {    private ArrayList<Double> data; /** Constructs an empty data set. @param maximumNumberOfValues the maximum this data set can...
Write a MARIE assembly language program that will read an “array” of positive decimal values stored...
Write a MARIE assembly language program that will read an “array” of positive decimal values stored in memory and output the smallest value. Use variable addr to store the location of the first data item. Use variable length to store the number of items in your array. Your code should be organized such that adding an additional array item would only involve adding the data line (ie. 021 dec 400) and updating the length variable (ie. length, dec 5). You...
Write recursive method to return true if a given array has element equal to employee emp,...
Write recursive method to return true if a given array has element equal to employee emp, or returns false otherwise. Array can be empty or not. //PRECONDITION: Varible n denotes the number of occupied positions in the array and must be non-negative. Employee class has method getSalary() that returns employee's salary, // and it has method boolean equals(Employee emp) that accept an employee object and returns true if employee calling the equals method is equal as employee emp, and returns...
Assume that you have an array of 100 elements representing the grades students are stored in...
Assume that you have an array of 100 elements representing the grades students are stored in memory. Suppose the grades are in IEEE single precision format. Write a MIPS program to compute the average of the students grades and store the result in register $f0. Assume the array base address is stored in register $s0 and a floating point value of 100 is stored in memory with it address given in register $s2.
(C++ only please) Write a function called maximum that takes an array of double values as...
(C++ only please) Write a function called maximum that takes an array of double values as a parameter and returns the largest value in the array. The length of the array will also be passed as a parameter. (Note that the contents of the array should NOT be modified.) Write a function called printReverse that takes an array of characters and the length of the array as parameters. It should print the elements of the array in reverse order. The...
Write a Java program to randomly create an array of 50 double values. Prompt the user...
Write a Java program to randomly create an array of 50 double values. Prompt the user to enter an index and prints the corresponding array value. Include exception handling that prevents the program from terminating if an out of range index is entered by the user. (HINT: The exception thrown will be ArrayIndexOutOfBounds) *Please do it in eclipse and this is java language*
Write a Java method that computes the future investment value at a given interest rate for...
Write a Java method that computes the future investment value at a given interest rate for a specified number of years. Your method should return the future investment value after calculation. The future investment is determined using the formula below:     futureInvestmentValue = investmentAmount * (1+monthlyInterestRate)numberOfYears*12 You can use the following method header: public static double futureInvestmentValue (double investmentAmount, double monthlyInterestRate, int years);
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT