Question

Java Assume there is an initialized array called examScores with of size 40 with values already...

Java

Assume there is an initialized array called examScores with of size 40 with values already loaded ExamScores Index [0] [1] [2] [3] [4] … [39] ExamScores Content 100 96 82 88 84 … 76 Write a method named getAverage that returns the average of the scores in the examScores array; this method uses the getTotal method to find and return the result.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is your code..

public class JavaExample {

static int getTotal(int arr[])
{
   int total=0;
   for (int i = 0; i < 40; i++)
   total += arr[i];
       return total;
}
static int getAverage(int a[], int n)
{
int sum = getTotal(a);
return sum / n;
}
  
public static void main(String[] args)
{
int [] examScores = {100,96,82,88,84,52,41,54,74,89,75,14,25,56,18,91,47,71,23,35,69,74,55,98,52,32,14,25,11,27,84,56,62,87,58,49,67,52,36,76};
   System.out.println(getAverage(examScores, 40));
}
}

# 10 *Untitled (not saved) X public class JavaExample { static int getTotal(int arr[]) Woo OWN int total=0; for (int i = 0; i

Add a comment
Know the answer?
Add Answer to:
Java Assume there is an initialized array called examScores with of size 40 with values already...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program that instantiates an array of integers named scores. Let the size of the...

    Write a program that instantiates an array of integers named scores. Let the size of the array be 10. The program then first invokes randomFill to fill the scores array with random numbers in the range of 0 -100. Once the array is filled with data, methods below are called such that the output resembles the expected output given. The program keeps prompting the user to see if they want to evaluate a new set of random data. Find below...

  • *JAVA* Assume that there already exists a class called ThreeDimensionalShape. Assume that this class has many...

    *JAVA* Assume that there already exists a class called ThreeDimensionalShape. Assume that this class has many subclasses, one of them being Cylinder. Assume that ThreeDimensionalShape has an instance method called getVolume() that returns the volume of the object (a double) and that this method is overridden in all of the subclasses. (You do not need to write any of these classes.) Write a method with this header: public static double volumeOfCylinders( ThreeDimensionalShapes[] shapes) It should return a value representing the...

  • 1.Write code for a Java method, printArray, that takes an int array as parameter and prints...

    1.Write code for a Java method, printArray, that takes an int array as parameter and prints it out, one element per line. public static void printArray (int[] values){ Methods that do NOT return a result have “void” as return type. Notice how an array parameter type is passed, int [] }// end printArray 2.Write code for a Java method that takes in as input parameter an integer number, say num, and returns a double array of size num with all...

  • Please help JAVA Create the following in Stack.java: An array of ints set to size 10...

    Please help JAVA Create the following in Stack.java: An array of ints set to size 10 to represent the Stack, an int variable for the index A constructor that sets the index to -1 A method called isEmpty (returns a boolean) that has no parameters. This method returns true if the Stack is empty and false if the Stack is not empty. true A method called push(returns a Boolean) that takes an int as a parameter. This method pushes, or...

  • This is java, please follow my request and use netbeans. Thank you. A3 15. 2D Array...

    This is java, please follow my request and use netbeans. Thank you. A3 15. 2D Array Operations Write a program that creates a two-dimensional array initialized with test data. Use any primitive data type that you wish. The program should have the following methods: • getTotal. This method should accept a two-dimensional array as its argument and return the total of all the values in the array. .getAverage. This method should accept a two-dimensional array as its argument and return...

  • JAVA question: Suppose we are performing a binary search on a sorted array called numbers initialized...

    JAVA question: Suppose we are performing a binary search on a sorted array called numbers initialized as follows: // index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 int[] numbers = {-30, -9, -6, -4, -2, -1, 0, 2, 4, 10, 12, 17, 22, 30}; ​ // search for the value -5 int index = binarySearch(numbers, -5); Write the indexes of the elements that would be examined by the binary search (the mid values...

  • Programming 5_1: Create a Java class named <YourName>5_1 In this class create a main method...

    Programming 5_1: Create a Java class named <YourName>5_1 In this class create a main method, but for now leave it empty. Then write a Java method getAverage which takes an array of integers as it’s argument. The method calculate the average of all the elements in the array, and returns that average. The method should work for an array of integers of any length greater than or equal to one. The method signature is shown below: public static double getAverage(...

  • I need it in JAVA Write a program that randomly populates an array of size 100,...

    I need it in JAVA Write a program that randomly populates an array of size 100, sorts it, and then finds the median. The random numbers must be from 0-99 and all integer values. Also since there is an even set of numbers the median is found by taking the mean of the two middle numbers (In other words the 50th and 51st). You have to code your own sorting method. You may not use a built in java sorter....

  • Implement a Java class that is called RainFall that uses a double array to store the...

    Implement a Java class that is called RainFall that uses a double array to store the amount of rainfall for each month of the year. The class should have only one instance variable of type double[]. Implement the following methods in the RainFall class: 1. A constructor that creates and initializes all entries in the array to be -1. 2. toString: a method that returns a one-line String representation of the object that includes 12 double numbers that represent the...

  • 23.1 Append to Oversize Array Java Help Given an oversize array with size1 elements and a...

    23.1 Append to Oversize Array Java Help Given an oversize array with size1 elements and a second oversize array with size2 elements, write a method that returns the first array with the elements of the second appended to the end. If the capacity of the oversize array is not large enough to append all of the elements, append as many as will fit. Hint: Do not construct a new array. Instead, modify the contents of the oversize array inside the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT