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

Design and implement a Java class (name it Summer Stats. java) that tracks stati

ID: 3693066 • Letter: D

Question

Design and implement a Java class (name it Summer Stats. java) that tracks statistics for summer job salaries for a group of people over several years. The only data field you need is a 2- Dimenssional array of values representing salaries. The rows the represents the people and the columns represent the years. The constructor method takes two integers representing the number of people and the number of years, then randomly generates the annual salaries and fills the array. Other class methods include the following: A method to return the index of the person having made the most money over the years. A method to return the index of the year when the highest salary was earned. A method to return the total amount of money made by a person (specified row index). A method to return the total amount of money made by all the people over the years. A method to return the index of the person who made the highest salary in a given year (specified by column index). A method to return a 1-Dimensional array of the average salary for each year. A method that return another 2-Dimensional array sorted by the total earning per person over the years. For example, if person in index 4 has the most earning over the years, then that would be the first row in the returned array. In other word, the array is sorted by the total of each row. Write a test program to create an object of this class and test all of the class methods on that objects. Use proper labels in your output. Document your code, and organize and space the outputs properly. Use escape characters and formatting objects when applicable.

Explanation / Answer

SummerStats.java

package org.students;

import java.util.Random;

public class SummerStats {
private int noofpeople;
private int noofyears;

private double salaries[][];

public SummerStats(int noofpeople, int noofyears)
{
   Random r = new Random();
  
   this.noofpeople = noofpeople;
   this.noofyears = noofyears;
   salaries=new double[noofpeople][noofyears];
   System.out.println(" Year1 Year2 Year3 Year4 Year5");
  
   for(int i=0;i<noofpeople;i++)
   {System.out.print("Person"+(i+1)+" :");
       for(int j=0;j<noofyears;j++)
       {
           salaries[i][j]=r.nextInt((300000 - 250000) + 1) + 250000;
           System.out.print(salaries[i][j]+" ");
       }
       System.out.println(" ");
   }//end of for loop
}  

//method to get which person earned highest salary over the years.
public int maxSalEarnedBy()
   { double maximum=salaries[0][0];
       int personIndex=0;
       for(int i=0;i<noofpeople;i++)
       {
           for(int j=0;j<noofyears;j++)
           {
               if(maximum<salaries[i][j])
               {
                   maximum=salaries[i][j];
                   personIndex=i;
               }
           }
       }
       return personIndex+1;
  
}
  
//method to get In which year the highest salary was earned.
   public int maxSalInYear()
   { double maxyear=salaries[0][0];
       int yearIndex=0;
       for(int i=0;i<noofpeople;i++)
       {
           for(int j=0;j<noofyears;j++)
           {
               if(maxyear<salaries[i][j])
               {
                   maxyear=salaries[i][j];
                   yearIndex=j;
               }
           }
       }
       return yearIndex+1;
  
}
  
   //method to get total salary earned by earch person over the years.

   public double [] totalAmountByIndividual()
   {
       double totMoney[]=new double[noofpeople];
       for(int i=0;i<noofpeople;i++)
       {
           for(int j=0;j<noofyears;j++)
           {
               totMoney[i]+=salaries[i][j];
           }
       }
       return totMoney ;
      
   }
  
   //method to get Total Amount Earned By all the persons over the years

   public double totMoneyByAll() {
       double totamt=0;
       for(int i=0;i<noofpeople;i++)
       {
           for(int j=0;j<noofyears;j++)
           {
               totamt+=salaries[i][j];
           }
       }
       return totamt;
   }
  
   //method to get which person who earn highest salary in that year .
   public int highSalEarnedPersonInyear(int yearNo) {
       double max=0.0;
       int person=0;
       if(yearNo==1)
       {
       max=salaries[0][0];
       }else if(yearNo==2)
       {
       max=salaries[0][1];  
       }
       else if(yearNo==3)
       {
       max=salaries[0][2];  
       }else if(yearNo==4)
       {
       max=salaries[0][3];  
       }else if(yearNo==5)
       {
       max=salaries[0][4];  
       }
       System.out.println(max+"----");
      
       for(int j=yearNo-1;j<yearNo;j++)
       {
           for(int i=0;i<noofpeople;i++)
       {
          
          
               if(salaries[i][j]>max)
               {
                   max=salaries[i][j];
                   System.out.println(max);
                   person=i;
               }
           }
       }
       return person+1;
   }
  
   //method to get average salary of each year.
   public double[] avgSalOfEachYear()
   {
   double avg[]=new double[noofpeople];
   double sum[]=new double[noofpeople];
   for(int j=0;j<noofyears;j++)
   {
       for(int i=0;i<noofpeople;i++)
   {
      
       sum[j]+=salaries[i][j];
   }
       avg[j]=sum[j]/noofpeople;
      
   }
   return avg;
  
}
  
   //method to get total sorted salaries of persons over the years
   public double[] sortOfTotalSalByEachPerson() {
       double sum[]=new double[noofpeople];
       //double personTotal[][]=new double[noofpeople][2];
       double personTotal[]=new double[noofpeople];
       for(int i=0;i<noofpeople;i++)
       {
           for(int j=0;j<noofyears;j++)
           {
               sum[i]+=salaries[i][j];
              
           }
           personTotal[i]=sum[i];
       }
      
      
       //sorting
       double temp=0;
       for (int i = 0; i < noofpeople; i++)
   {
   for (int j = i + 1; j < noofpeople; j++)
   {
   if (personTotal[i] > personTotal[j])
   {
   temp = personTotal[i];
   personTotal[i] = personTotal[j];
   personTotal[j] = temp;
   }
   }
   }
  
       return personTotal;
      
   }
}

____________________________________________________________________________________

Test.java

package org.students;

import java.util.Scanner;

public class Test {

   public static void main(String[] args) {
       Scanner sc=new Scanner(System.in);
   System.out.print("Enter Number of people ::");
   int noofpeople=sc.nextInt();
   System.out.print("Enter Number of years ::");
   int noofyears=sc.nextInt();
   //creating an object by passing the parameters.
   SummerStats st=new SummerStats(noofpeople,noofyears);
  
   //calling the method to get which person earned highest salary over the years.
   int personEarnedHighestSal=st.maxSalEarnedBy();
   System.out.println("The Person who earned Highest Salary over "+noofyears+" years is :: Person "+personEarnedHighestSal);
  
   //calling the method to get In which year the highest salary was earned.
   int highestSalEarnedInTheYear=st.maxSalInYear();
   System.out.println("The Highest salary was earned over "+noofyears+" in the year :: Year "+highestSalEarnedInTheYear);
  
   //calling the method to get total salary earned by earch person over the years.
   double totAmt[]=st.totalAmountByIndividual();
   for(int i=0;i<noofpeople;i++)
   {
      
       System.out.println("Total Salary earned by Person "+(i+1)+" over "+noofyears+" years is ::"+totAmt[i]);
      
   }
   //calling the method to get Total Amount Earned By all the persons over the years
double totalamt=st.totMoneyByAll();
System.out.println("Total Amount Earned By all the persons over the years is ::"+totalamt);
  
//calling the method to get which person who earn highest salary in that year .
System.out.print("Enter the year number to know which person who earn highest salary in that year (1 to 5)::");
int yearNo=sc.nextInt();
int personI=st.highSalEarnedPersonInyear(yearNo);
System.out.println("The Person who earned Highest salary in the year "+yearNo+" is :: Person "+personI);
  
//calling the method to get average salary of each year.
double avgOfEach[]=st.avgSalOfEachYear();
for(int i=0;i<avgOfEach.length;i++)
{
   System.out.println("The average Salary of year "+(i+1)+" is:"+avgOfEach[i]);
}
  
//calling a method to get total sorted salaries of persons over the years
double sort[]=st.sortOfTotalSalByEachPerson();
System.out.print("The Total Sorted salaries over the People are :");
for(int i=0;i<sort.length;i++)
{
   System.out.print(sort[i]+" ");
}
  
   }

  

}

_________________________________________________________________________________________

output:

Enter Number of people ::5
Enter Number of years ::5
   Year1   Year2   Year3   Year4   Year5
Person1 :259912.0 274258.0 293815.0 291204.0 260121.0

Person2 :252407.0 261441.0 283459.0 298686.0 283071.0

Person3 :280246.0 279388.0 268682.0 269414.0 250793.0

Person4 :267536.0 263691.0 269897.0 256696.0 250004.0

Person5 :297096.0 287225.0 289705.0 297818.0 255051.0

The Person who earned Highest Salary over 5 years is :: Person 2
The Highest salary was earned over 5 in the year :: Year 4
Total Salary earned by Person 1 over 5 years is ::1379310.0
Total Salary earned by Person 2 over 5 years is ::1379064.0
Total Salary earned by Person 3 over 5 years is ::1348523.0
Total Salary earned by Person 4 over 5 years is ::1307824.0
Total Salary earned by Person 5 over 5 years is ::1426895.0
Total Amount Earned By all the persons over the years is ::6841616.0
Enter the year number to know which person who earn highest salary in that year (1 to 5)::5
260121.0----
283071.0
The Person who earned Highest salary in the year 5 is :: Person 2
The average Salary of year 1 is:271439.4
The average Salary of year 2 is:273200.6
The average Salary of year 3 is:281111.6
The average Salary of year 4 is:282763.6
The average Salary of year 5 is:259808.0
The Total Sorted salaries over the People are :1307824.0 1348523.0 1379064.0 1379310.0 1426895.0

______________________________________________________________________________________

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