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

Write a Basketball Stats class that stores the points for 6 players in an array

ID: 3825498 • Letter: W

Question

Write a Basketball Stats class that stores the points for 6 players in an array of integers. The program should have methods that return the following:

the average points

the highest points

the lowest points

the range of points (highest points - lowest points)

the number of players who scored double digits (more than 10)

Demonstrate the class in a complete program in two java files (ex. one file the stats class, and test it with the statsDemo.java)... TWO .JAVA FILES IS THE MOST IMPORTANT PART!!!!

Explanation / Answer

/* Stats Class :File 1 */

/* Class Stats containing all required methods */
public class Stats {
   public int[] arr=new int[6];//array to store points
   /* constructor to store points array passed from StatsDemo class to Stats class */
   Stats(int[] arr){
       this.arr=arr;
   }
   /* average method */
   public static double average(int[] arr){
       int sum=0;
       for(int i=0;i<arr.length ;i++)
           sum=sum+arr[i];
       double avg=(sum/arr.length);
       return avg;
   }
   /* highest method */
   public static int highest(int[] arr){
       int max=arr[0];
       for(int i=0;i<arr.length;i++){
           if(max<=arr[i])
               max=arr[i];
       }
       return max;
   }
   /* lowest method */
   public static int lowest(int[] arr){
       int min=arr[0];
       for(int i=0;i<arr.length;i++){
           if(min>=arr[i])
               min=arr[i];
       }
       return min;
   }
   /* range method */
   public static int range(int[] arr){
       int max=arr[0];
       int min=arr[0];
       for(int i=0;i<arr.length;i++){
           if(max<=arr[i])
               max=arr[i];
           else if(min>=arr[i])
               min=arr[i];
       }
       int range=max-min;
       return range;
   }
   /* method to count double digit score i.e more than equal to 10*/
   public static int doubleDigits(int[] arr){
       int count=0;
       for(int i=0;i<arr.length;i++){
           if(arr[i]>=10)
               count++;
       }
       return count;
   }
}

/******************************************************/

/*********StatsDemo Class file 2 ****/

import java.util.Scanner;

/* class to check Stats class */
public class StatsDemo {
   public static void main(String[] args) {
       int[] points=new int[6];//array to store points of 6 players
       System.out.println("Please enter the points of 6 players : ");
       Scanner input=new Scanner(System.in);
       for(int i=0;i<6;i++)
           points[i]=input.nextInt();//taking the input from the user
       Stats st=new Stats(points); //making the object of Stats class and pasing points array as a constructor parameter
       System.out.println("Average of points : "+st.average(points));//calling average method
       System.out.println("Highest of points : "+st.highest(points));//calling highest method
       System.out.println("Lowest of points : "+st.lowest(points)); //calling lowest method
       System.out.println("Range of points : "+st.range(points));//calling range method
       System.out.println("Number of players who scored double digits : "+st.doubleDigits(points));//calling count of double digit scorers method
      
      
   }
}

/* Note: Please ask in case of any doubt,thanks */

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