Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Your assignment is to calculate averages given a list of input. First ask the us

ID: 644410 • Letter: Y

Question

Your assignment is to calculate averages given a list of input. First ask the users how many numbers (doubles) she will enter. Then prompt for that many numbers.

Then output the following values min,max, sum, mean, median, mode - in that order. For the purposes of this exercise, you may assume that either 1 mode exists or no modes exist. (e.g. in {1,3,3,4,4}, there is no mode since there are 2 3's and 2 4's, but {1,3,3,4} has a mode of 3). If no mode exists, you can output the String "none".

The median is determined by finding the middle number. If no such number exists, it is calculated by taking the mean of the 2 middle numbers.

Hint: In order to accomplish median/mode calculations it might be useful for you to keep the list of numbers in some sorted order. i.e. on every insertion, place the number in the "correct" place.

Example (note commented descriptions should not be printed - they are for your information only):

Explanation / Answer

import java.util.Scanner;
public class HelloWorld{
public static void main(String []args){
int n, c, d, swap,sum=0;
Scanner in = new Scanner(System.in);
System.out.println("Input number of integers to sort");
n = in.nextInt();
int array[] = new int[n];
System.out.println("Enter " + n + " integers");
for (c = 0; c < n; c++){
array[c] = in.nextInt();
sum=sum+array[c];
}

for (c = 0; c < ( n - 1 ); c++) {
for (d = 0; d < n - c - 1; d++) {
if (array[d] > array[d+1]) /* For descending order use < */
{
swap = array[d];
array[d] = array[d+1];
array[d+1] = swap;
}
}
}
System.out.println("Sorted array:");
for (c = 0; c < ( n - 1 ); c++) {
System.out.println(array[c]);
}
  
  
System.out.println("Sum="+sum);
System.out.println("Max="+array[n-1]);
System.out.println("Min="+array[0]);
System.out.println("Mean="+sum/n);
  
double median = 0;
double mid=0;
if(n%2 == 0)
{
int temp=(n/2)-1;
for(int i=0;i<n;i++)
{
if(temp==i || (temp+1)==i)
{
mid=mid+array[i];
}
}
mid=mid/2;
System.out.println("Median value is: "+mid);
}
else
{
int temp=(n/2);
for(int i=0;i<n;i++)
{
if(temp==i)
{
mid=array[i];
System.out.println("Median value: "+mid);
}
}
}
//Mode calculation
int i,j,z, tmp, maxCount, modeValue;
int[] tally=new int[n];
for(i=0;i<n;i++)
{
for(j=0;j<n-i;j++)
{
if(j+1!=n)
{
if(array[j]>array[j+1])
{
tmp=array[j];
array[j]=array[j+1];
array[j+1]=tmp;
}
}
}
}
for (i = 0; i < n; i++)
{
for(z=i+1;z<n;z++)
{
if(array[i]==array[z])
{
tally[i]++;
}
}
}
maxCount = 0;
modeValue = 0;
for (i = 0; i <n; i++)
{
if (tally[i] > maxCount)
{
maxCount = tally[i];
modeValue = array[i];
}
}
System.out.println("Mode value is :"+modeValue);
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote