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 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 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);
Write a program that asks the user to enter 3 grades and computes the minimum and...
Write a program that asks the user to enter 3 grades and computes the minimum and the maximum of those 3 grades and prints it. Hint: Use the Math.min() and Math.max() methods. This program will compute the smallest and highest of 3 grades entered by the user. Enter 3 grades separated by a space: 100 85.3 90.5 Smallest: 85.3 Highest: 100.0 Bye
Write a function double mysqrt( double x ) which computes the value of the square root...
Write a function double mysqrt( double x ) which computes the value of the square root of x using the bisection method. First you need to set the left and right bounds for x. If 0<x<1 then lt = x and rt = 1 and the sqrt(x) is somewhere in between. If x > 1 then lt = 1 and rt = x and sqrt(x) is somewhere in between. In a loop you need to compute the mid value between...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT