Hy. I wrote this piece of code
import java.util.Scanner;
public class SportsEvents {
public static void main(String[] args) {
String[] contestants = getcontestants();
int[] score=getscores();
System.out.println("The maximum score is: "+getMaxValue(score));
System.out.println("The minimum score is: "+getMinValue(score));
System.out.println("The average is: "+getAverage(score));
}
public static String[] getcontestants()
{
int numcontestants=1;
String name[] = new String[numcontestants];
for(int j=0;j<numcontestants;j++){
Scanner ip=new Scanner(System.in);
System.out.println("Enter contestant's name");
name[j]=ip.nextLine();
}
return name;
}
public static int[] getscores()
{
int numscores=8;
int score[] = new int[numscores];
for (int a=0;a<numscores;a++){
Scanner ip=new Scanner(System.in);
System.out.println("Enter the scores");
score[a]=ip.nextInt();
}
return score;
}
public static int getMaxValue(int[] array) {
int maxValue = array[0];
for (int i = 1; i < array.length; i++) {
if (array[i] > maxValue) {
maxValue = array[i];
}
}
return maxValue;
}
public static int getMinValue(int[] array) {
int minValue = array[0];
for (int i = 1; i < array.length; i++) {
if (array[i] < minValue) {
minValue = array[i];
}
}
return minValue;
}
public static int getAverage(int[] people) {
int sum = 0;
for (int i=0; i < people.length; i++) {
sum = sum + people[i];
}
int result = sum / people.length;
return result;
}
}
As you can see, the user enters a name and 8 scores and the computers find the biggest score, the lowest score, and the average. I want a non-void method that will give a summary of everything but I don't know how to do it. Ex: If I entered James as a name and the numbers 1-8, I want it to print: The contestant is James, his highest score was 8. His lowest score was 1. His average is 49. Thank you and tell me if it's confusing!!