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

Suppose you are commissioned by the Australian Football Association (AFL) to wri

ID: 3712616 • Letter: S

Question

Suppose you are commissioned by the Australian Football Association (AFL) to write a program designed to produce statistics based on complete scores recorded in a season. These scores are kept in a file called afl.txt (available on interact resources). You are also given the following information about a football season:

League consists of 18 football teams

There are 22 rounds in each season

In each round teams play against each other and the score of each team is recorded as an integer and kept in the text file referred to above (aft.txt)

Your task is to write a complete java program (a java class with the main method) called ProcessScores, which will read the scores from the text file provided, store the scores in an array of integers and then using a number of independent static methods, calculate and display the required statistics relating the afl scores.

The java class you are required to author will contain the following static methods:

lowest will take the array of scores as an argument and return the lowest score in the season

highest will take the array of scores as an argument and return the highest score in the season

range will take the array of scores as an argument and return the difference between the highest score and the lowest score in the season

average will take the array of scores as an argument and return the average of all scores in the season

median will take the array of scores as an argument and return the median score in the season

mode will take the array of scores as an argument and return the mode of the scores in the season

Note that all of the methods described above, should be static methods; user defined methods (you have the write the definition of each yourself); and completely independent of each other (you should not invoke anyone of them within the other method definition). Also, the original array of scores should not be modified by any of the methods.

Suppose you are commissioned by the Australian Football Association (AFL) to write a program designed to produce statistics based on complete scores recorded in a season. These scores are kept in a file called afl.txt (available on interact resources). You are also given the following information about a football season:

League consists of 18 football teams

There are 22 rounds in each season

In each round teams play against each other and the score of each team is recorded as an integer and kept in the text file referred to above (aft.txt)

Your task is to write a complete java program (a java class with the main method) called ProcessScores, which will read the scores from the text file provided, store the scores in an array of integers and then using a number of independent static methods, calculate and display the required statistics relating the afl scores.

The java class you are required to author will contain the following static methods:

lowest will take the array of scores as an argument and return the lowest score in the season

highest will take the array of scores as an argument and return the highest score in the season

range will take the array of scores as an argument and return the difference between the highest score and the lowest score in the season

average will take the array of scores as an argument and return the average of all scores in the season

median will take the array of scores as an argument and return the median score in the season

mode will take the array of scores as an argument and return the mode of the scores in the season

Note that all of the methods described above, should be static methods; user defined methods (you have the write the definition of each yourself); and completely independent of each other (you should not invoke anyone of them within the other method definition). Also, the original array of scores should not be modified by any of the methods.

Explanation / Answer

import java.io.*;
import java.util.*;

public class Demo151{

    public static void ProcessScore(int[] data){
       try {
           FileInputStream fin = new FileInputStream("aft.txt");
           Scanner fc = new Scanner(fin);
           int count = 0;
           for (int i = 0; i<22; i++){
              for (int j = 0; j<18; j++){
                  data[count] = fc.nextInt();
                  count++;
              }
           }          
       }
       catch (Exception e){
           e.printStackTrace();
       }
    }
    public static int lowest(int[] data){
        int min = data[0];
        for (int i = 0; i<data.length; i++){
            if (data[i] < min)
               min = data[i];
        }
        return min;
    }
    public static int highest(int[] data){
        int max = data[0];
        for (int i = 0; i<data.length; i++){
            if (data[i] > max)
               max = data[i];
        }
        return max;
    }
    public static int range(int[] data){
        int max = data[0];
        for (int i = 0; i<data.length; i++){
            if (data[i] > max)
               max = data[i];
        }
        int min = data[0];
        for (int i = 0; i<data.length; i++){
            if (data[i] < min)
               min = data[i];
        }
        return (max - min);
    }
    public static int average(int[] data){
        double sum = 0;
        for (int i = 0; i<data.length; i++){
            sum = sum + data[i];
        }
        return sum/count;
    }
    public static int median(int[] data){
        for (int i = 0; i<count; i++){
           for (int j = i+1; j<count; j++){
                if (data[i] > data[j]){
                   int temp = data[i];
                   data[i] = data[j];
                   data[j] = temp;
                }
           }
        }
        int mid = 1 + (count-1)/2;
        return data[mid];
    }

    public static int mode(int[] data){
        int mode = data[0];
        int maxCount = 0;
        for (int i = 0; i<count; i++){
           int count = 0;
           for (int j = 0; j<count; j++){
               if (data[i] == data[j])
                  count++;
           }
           if (count > maxCount){
              maxCount = count;
              mode = data[i];
           }
        }

        return mode;
    }

    public static void main(String[] arga){
       ProcessScores(scores);
       int low = lowest(scores);
       int high = highest(scores);
       int rng = range(scores);
       double avg = average(scores);
       int mdn = median(scores);
       int mde = mode(scores);
       System.out.println("Lowest Score:" + low);
       System.out.println("Highest Score:" + high);
       System.out.println("Range:" + rng);
       System.out.println("Average Score:" + avg);
       System.out.println("Median :" + mdn);
       System.out.println("Mode :" + mde);
    }
}

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