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

Write a java class (and a client class to test it) that encapsulates statistics

ID: 3810857 • Letter: W

Question

Write a java class (and a client class to test it) that encapsulates statistics for summer job salaries for a group of people over several years. Your only instance variable should be a two-dimensional array of values representing salaries. Dimension 1 (rows) represents the people and dimension 2 (cols) represents the year of the summer job. Your constructor can simply take two integers representing the number of people and the number of years, then randomly generate the salaries and fill the array. You should include the following methods:

Overloaded Constructor, accessor, mutator, toString(), and equals()

A method returning the value of the person having made the most money over the years

A method returning the year (cols) when the highest salary was earned

A method returning the total amount of money made by all the people over the years

Explanation / Answer

i have done it in NetBeans IDE


package summersalariesstatastics;

import java.util.Random;

public class SummerSalariesStatastics {
private int Peoples,Years;
private int array[][],colArray[],rowArray[];
public SummerSalariesStatastics(int peoples,int years){
this.Peoples = peoples;
this.Years = years;
array = new int[peoples][years];
rowArray = new int[peoples];
colArray = new int[peoples];
}
public void setSalaries(){
int i,j;
Random r = new Random();
for(i = 0 ;i < this.Peoples; i++){
for(j = 0 ;j < this.Years; j++){
array[i][j] = r.nextInt(10000);
}
}
System.out.println(" Random Filled Array");
for(i = 0 ;i < this.Peoples; i++){
for(j = 0 ;j < this.Years; j++){
System.out.print(array[i][j]+" ");
}
System.out.println();
}
}
  
public int getMostMoneyPerson(){
int i,j,max,sum = 0,k=0;
for(i = 0;i < Peoples;i++){
for(j = 0;j < Years;j++){
//System.out.println("i = " + i + " j = "+j);
sum = sum + array[i][j];
}
rowArray[k] = sum;
sum = 0;
k++;
}
//for(i = 0;i<rowArray.length;i++)
// System.out.print(rowArray[i]+" ");
  
max = rowArray[0];
  
int index = 0;
for(i = 0;i < rowArray.length;i++){
if(rowArray[i] >= max){
max = rowArray[i];
index = i;
}
}

return index;
}
public int getYearHighSalary(){
return 0;
}
public int getTotalAmoutMoney(){
int i,j,max,sum = 0,k=0;
for(i = 0;i < Peoples;i++){
for(j = 0;j < Years;j++){
//System.out.println("i = " + i + " j = "+j);
sum = sum + array[i][j];
}
rowArray[k] = sum;
sum = 0;
k++;
}
sum = 0;
for(i = 0; i < rowArray.length;i++){
sum = sum + rowArray[i];
}
return sum;
}
public static void main(String[] args) {
SummerSalariesStatastics sss = new SummerSalariesStatastics(5,5);
sss.setSalaries();
System.out.println(" the person having made the most money over the years = "+sss.getMostMoneyPerson()+" ");
System.out.println("Total amout by all peoples = "+sss.getTotalAmoutMoney());

}
  
}

output:

run:
   Random Filled Array
8131   9237   3807   5512   9504  
4483   1392   8467   9032   9513  
2079   1650   2110   7587   5907  
659   706   1244   4415   8460  
9966   4913   6924   1552   2527  

the person having made the most money over the years = 0

Total amout by all peoples = 129777
BUILD SUCCESSFUL (total time: 0 seconds)

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