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

Write in JAVA Write a class (and a client class to test it) that encapsulates st

ID: 3848226 • Letter: W

Question

Write in JAVA

Write a 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 I represents the people and dimension 2 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: method returning the index of the person having made the most money over the years method returning the year when the highest salary was earned method returning the total amount of money made by all the people over the years

Explanation / Answer

// JobSalaries.java
import java.util.Random;
class JobSalaries
{

int[][] salaries;

public JobSalaries(int noOfPeople, int noOfYears) {
salaries = new int[noOfPeople][noOfYears];

Random r = new Random();
for(int i = 0; i < noOfPeople; i++)
{
for(int j = 0; j < noOfYears; j++)
{
salaries[i][j] = r.nextInt(30000) + 10000;
}
}
}

public int personMadeMostMoneyIndex()
{
int[] temp = new int[salaries.length];
for(int i = 0; i < salaries.length; i++)
{
for(int j = 0; j < salaries[i].length; j++)
{
temp[i] += salaries[i][j];
}
}
int index = 0;
for(int i = 0; i < temp.length - 1; i++)
{
if(temp[i] < temp[i+1])
index = i+1;
else index = i;
}
return index;
}

public int highestSalaryYear()
{
int year = 0;
int[] salaryByYear = new int[salaries[0].length];
for(int j = 0; j < salaries[0].length; j++)
{
for(int i = 0; i < salaries.length; i++)
{
salaryByYear[j] += salaries[i][j];
}
}
for(int i = 0; i < salaryByYear.length - 1; i++)
{
if(salaryByYear[i] < salaryByYear[i+1])
year = i+1;
else
year = i;
}
return year + 1;
}

public int totalMoney()
{
int totalSalary = 0;
for(int i = 0; i < salaries.length; i++)
{
for(int j = 0; j < salaries[i].length; j++)
{
totalSalary += salaries[i][j];
}
}
return totalSalary;
}
}



//Driver.java

import java.util.Scanner;
public class Driver
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
// Prompting user to enter the number of people and number of years of the summber job.
System.out.print("Enter the number of employees : ");
int emps = sc.nextInt();
System.out.print("Enter the number of years : ");
int years = sc.nextInt();
// creating object with user specified data and displaying details
JobSalaries js = new JobSalaries(emps, years);
System.out.println("The index of the person having made the most money over the years : " + js.personMadeMostMoneyIndex());
System.out.println("The year when the highest salary was earned : " + js.highestSalaryYear());
System.out.println("The total amount of money made by all the people over the years : " + js.totalMoney());
}
}

/*
output:

Enter the number of employees : 5
Enter the number of years : 10
The index of the person having made the most money over the years : 4
The year when the highest salary was earned : 10
The total amount of money made by all the people over the years : 1232438

*/

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