Question #8914

Your lecture wishes to store the exam marks for java,and perform an analysis of the marks.The marks are expressed as a percentage.There are 15 students that wrote the exam. Write the java program that will enable her to:
-input the marks for each student and store in an array called Supp.The input must be validated befoe being stored
-Determine and display the highest and lowest mark.
-Determine and display the average mark for the supplementary exam.
-Determine and display the mean and median(mean is calculated as the average of the lowest and highest marks)
E.g input:15 27 38 2 98 42 87 92 99 13 5 72 67 2 1
Output:
highest:99
lowest:1
median:38
average:44
mean:50
i'd be grateful for your help.
NB: URGENT!

Expert's answer

import java.util.Arrays;

import java.util.Scanner;

public class Main {

private static Scanner input =new Scanner(System.in);

private static int Supp[]=new int[15];

public static void main(String[] args) {

for(int i=0;i<15;i++){

System.out.print("Input the mark for student "+(i+1)+": ");

Supp[i]=input.nextInt();

}

System.out.println("Highest "+Max(Supp));

System.out.println("Lowest "+Min(Supp));

System.out.println("Median "+Median(Supp));

System.out.println("Average "+Average(Supp));

System.out.println("Mean "+Mean(Supp));

}

//Median

private static double Median(int arayofNumber[]){

double median=0;

Arrays.sort(arayofNumber);

median=arayofNumber[7];

return median;

}

//Mean

private static double Mean(int arayofNumber[]){

double mean=0;

mean=(Min(arayofNumber)+Max(arayofNumber))/2;

return mean;

}

//Sum

private static double Sum(int arayofNumber[]){

int sum=0;

for(int i=0;i<15;i++){

sum+=arayofNumber[i];

}

return sum;

}

//Function Min - smallest element in the array

public static double Min(int arayofNumber[]){

int min=arayofNumber[0];

for(int i=0;i<15;i++){

if(arayofNumber[i]<arayofNumber[0]){

min=arayofNumber[i];

}

}

return min;

}

//Function Max - largest element in the array

public static double Max(int arayofNumber[]){

int max=arayofNumber[0];

for(int i=0;i<15;i++){

if(arayofNumber[i]>arayofNumber[0]){

max=arayofNumber[i];

}

}

return max;

}

private static double Average(int[] arayofNumber) {

double average=0;

average=Sum(arayofNumber)/15;

return average;

}

}

import java.util.Scanner;

public class Main {

private static Scanner input =new Scanner(System.in);

private static int Supp[]=new int[15];

public static void main(String[] args) {

for(int i=0;i<15;i++){

System.out.print("Input the mark for student "+(i+1)+": ");

Supp[i]=input.nextInt();

}

System.out.println("Highest "+Max(Supp));

System.out.println("Lowest "+Min(Supp));

System.out.println("Median "+Median(Supp));

System.out.println("Average "+Average(Supp));

System.out.println("Mean "+Mean(Supp));

}

//Median

private static double Median(int arayofNumber[]){

double median=0;

Arrays.sort(arayofNumber);

median=arayofNumber[7];

return median;

}

//Mean

private static double Mean(int arayofNumber[]){

double mean=0;

mean=(Min(arayofNumber)+Max(arayofNumber))/2;

return mean;

}

//Sum

private static double Sum(int arayofNumber[]){

int sum=0;

for(int i=0;i<15;i++){

sum+=arayofNumber[i];

}

return sum;

}

//Function Min - smallest element in the array

public static double Min(int arayofNumber[]){

int min=arayofNumber[0];

for(int i=0;i<15;i++){

if(arayofNumber[i]<arayofNumber[0]){

min=arayofNumber[i];

}

}

return min;

}

//Function Max - largest element in the array

public static double Max(int arayofNumber[]){

int max=arayofNumber[0];

for(int i=0;i<15;i++){

if(arayofNumber[i]>arayofNumber[0]){

max=arayofNumber[i];

}

}

return max;

}

private static double Average(int[] arayofNumber) {

double average=0;

average=Sum(arayofNumber)/15;

return average;

}

}

## Comments

## Leave a comment