1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
yarga [219]
3 years ago
6

Write a Java Program that can compute the mean, median, the highest, and the lowest of the students’ scores in a class. First, t

he user inputs the number of students in the class and you capture this number. Then the user inputs the grades of all the students in the class. After capturing all the inputs, your program should output the mean, the median, the highest, and the lowest.
Computers and Technology
1 answer:
slava [35]3 years ago
4 0

Answer:

import java.util.Arrays; // The Array class allows for array operations

import java.util.Scanner; // The Scanner class allows for user's inputs

public class Statistics {

public static void main(String[] args) {

 // create an object of the Scanner class

 Scanner input = new Scanner(System.in);

 System.out.println("Please enter the number of students");

 // Using "input" which is an object of the Scanner class,

 // get the number of students.

 int noOfStudents = input.nextInt();

 // Create an array of scores whose length is equal to the number of students

 // Array is of type double as students' scores could be floating point numbers

 double[] scores = new double[noOfStudents];

 // Create a loop that cycles as many times as the number of students.

 // Each loops asks the user to enter the score of each student

 // Initialize the scores array with each score at every loop

 int i = 0; // This is a counter for the loop

 while (i < noOfStudents) {

  System.out.println("Enter score for student " + (i + 1));

  scores[i] = input.nextDouble();

  i++; // increment counter at every loop

 }

 // At the end of the loop above, the scores array should be completely

 // initialized

 // You might want to print out the scores before sorting

 System.out.println(Arrays.toString(scores));

 // Sort the scores array so as to be able to calculate the median

 Arrays.sort(scores);

 // Print out the results by calling the necessary methods

 System.out.println("Mean score : " + mean(scores));

 System.out.println("Median score is : " + median(scores));

 System.out.println("Highest score : " + highest(scores));

 System.out.println("Lowest score : " + lowest(scores));

}

// Method to calculate the mean of the scores in the scores array

// Initialize a variable, sum, to zero to allow for cumulative addition of the

// array elements.

// Loop through the scores array adding up the array elements cumulatively

// Divide the result of the sum by the length of the array to get the

// mean(average).

// In this case, scores array is represented by arr

public static double mean(double[] arr) {

 double sum = 0;

 for (int i = 0; i < arr.length; i++) {

  sum += arr[i];

 }

 return sum / arr.length; // Return the mean (average).

 

} // End of the mean method  

 

 

// Method to calculate the median of the scores in the scores array

// Median is the middle element in a sorted set of elements

// If the length(number of elements) of the sorted set of elements is even

// there will be two elements representing the median.

// To break this tie, the average of the two elements is found.

// In this case, scores array is represented by arr

public static double median(double[] arr) {

 //Check if the length of the array is even or not.

 //This will help to break the tie if it occurs.

 

 if (arr.length % 2 != 0) {

  int mid = (arr.length + 1) / 2;   //mid represents the middle number

  return arr[mid - 1];    // Because arrays are indexed from zero(0), 1 is subtracted from mid

 } else {

  int mid = (arr.length) / 2;

  return (arr[mid] + arr[mid + 1]) / 2.0;

 }

} // End of the method median

 

 

// Method to calculate the highest of the scores in the scores array

// In this case, the scores array is represented by arr

public static double highest(double[] arr) {

 

 //Declare and initialize a temp variable to hold the first element in the array

 double temp = arr[0];

 //Loop through the array starting at the second position since the value in the first position has been stored in a temp variable

 for (int i = 1; i < arr.length; i++) {

  //At every loop, check if there is a number greater than the one stored in the temp variable

  //If there is, replace temp with such number

  if (arr[i] > temp) {

   temp = arr[i];

  }

 }

 return temp; //Return the highest number

} // End of the method highest

 

 

// Method to calculate the lowest of the scores in the scores array

// In this case the scores array is represented by arr

public static double lowest(double[] arr) {

 

 //Declare and initialize a temp variable to hold the first element in the array

 double temp = arr[0];

 //Loop through the array starting at the second position since the value in the first position has been stored in a temp variable

 for (int i = 1; i < arr.length; i++) {

  //At every loop, check if there is a number less than the one stored in the temp variable

  //If there is, replace temp with such number

  if (arr[i] < temp) {

   temp = arr[i];

  }

 }

 return temp; //Return the lowest number

} // End of the method lowest

}

Explanation:

Explanations are explicitly written in the answer above in comments.

The source code file (Statistics.java) has been attached to this answer.

Hope this helps!.

Download java
You might be interested in
A popular use of cd-rw and cd-r discs is to create audio cds. what is the process of copying audio and/or video data from a purc
Savatey [412]
<span>This process is called ripping. Ripping occurs when the audio or video content of a disc is extracted and copied onto any other digital media. This process does not damage the original disc or the data it contains. This process requires specific software to be successful.</span>
4 0
3 years ago
Name various phases of SDLC in Rational Unified Process (RUP)
ss7ja [257]

Answer:

The RUP is an agile software development type of methodologies, and it consists of four phases, which are  

• inception,  

• elaboration,  

• construction  

• and transition.  

The main aim of the RUP is to come up with a software that is very high in quality, and with a predictable budget, as well as it must be according to the time frame.  

Explanation:

Please check the answer section.

6 0
3 years ago
Beginning in cell B21, complete the series of substitution values ranging from $35 to $45 in increments of $2.50 vertically down
abruzzese [7]

In order to complete the series of substitution values from $35 to $45 in increments of $2.50, follow these steps:

  • Input $35 in B21.
  • Highlight B21 to B26.
  • Go to the Home tab.
  • Go to the Editing ribbon.
  • Click on Fill.
  • Click on Series.
  • Step Value = 2.50
  • Stop Value = 45.
  • Click Okay.

<h3>How can you complete a series of Substitution values?</h3>

First input the value you are to start with in the cell you are to start with. In this case that means putting $35 in Cell B21.

Highlight B21 to B26 and then go to the Home tab. Go to the Editing ribbon at the bottom right and click on Fill. Then go to Series and input the step value as 2.50 and the stop value as 45. Click okay and the range will appear.

Find out more on spreadsheet functions at brainly.com/question/1395170.

4 0
2 years ago
What will be the value of ans after the following code has been executed?
Lesechka [4]

Answer:

Option B 120

Explanation:

There are three variables,<em> ans, x </em>and <em>y</em> given in the code. In beginning, the variable. <em>ans,</em> holds value of 10.  And variable <em>x</em> and <em>y</em> hold value of 65 and 55, respectively. Since the value held by x is bigger than one held by y, the if condition is met and the statement ans = x + y will run. The execution of this statement will total x with y -> 65 + 55 and the initial value of <em>ans is </em>overwritten by the addition result which is 120.

7 0
3 years ago
Read 2 more answers
Dave has to create animations for a game. Which tool can Dave use?
Shtirlitz [24]
What are your answer choices?
8 0
3 years ago
Other questions:
  • how do you make a circuit so 1 switch will turn on/off all the lights(3 lights) and a second switch will change the lights from
    14·2 answers
  • What is a flash player?
    9·2 answers
  • 2. What are the pros and cons of Toyota structure?
    13·1 answer
  • What is an online recommendation engine?
    12·1 answer
  • Which of the following actions is an example of "window dressing?" a. Using some of the firm’s cash to reduce long-term debt. b.
    13·1 answer
  • What is the different between ethical and legal issues?​
    6·1 answer
  • How to use repl.it css
    7·1 answer
  • Make me die from laughter i will give brainlyest for the best joke
    11·1 answer
  • Which programming paradigm does the programming language JavaScript follow?
    14·1 answer
  • Write a recursive function named canmakesum that takes a list of * integers and an integer target value (sum) and returns true i
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!