Programming in Java Week 6 Assignment Greenway Consulting surveyed the employees
ID: 3661473 • Letter: P
Question
Programming in Java Week 6 Assignment Greenway Consulting surveyed the employees of three companies Alhermit, Logway, and Felter Corporations to evaluate the salaries for the employees. You will write a program that does the following: Put the data below into a multi-dimensional array Prompts the user for the company they would like employee salary statistics. Write a method that returns the average employee salary as a double. Pass the company number and employee Wages to this method. Write a method that returns the total employee salary as an int. Pass the company number and employee Wages to this method. Write a method that returns the number of employees as an int. Pass the company number and employee Wages to this method. In the main method call the other methods and out put the results. Make sure you comment your code and take a screenshot of the results. Then submit it with your java code. The Java coding should be in a text file or in a word processing document. Data Alhermit Logway Felter 49920 45519 54619 50831 47373 48339 39430 36824 44260 54697 51229 44390 41751 36966 39732 36110 40332 44073 41928 53294 53308 48460 44907 35459 39714 36050 52448 49271 51574 38364 51713 39758 39990 38903 53847 47373 Grading Criteria Points The Student’s code works 20 points The Student’s code includes all program requirements 40 points The Student compiled and ran the program 20 points The Student properly commented the code 20 points Total 100 Points
Explanation / Answer
Greenway.java
import java.io.*;
public class Greenway {
public static void main(String[] args) throws IOException
{
int alhermit[]={49920,50831,39430,54697,41751,36110,41928,48460,39714,49271,51713,38903};
int logway[]={45519,47373,36824,51229,36966,40332,53294,44907,36050,51574,39758,53847};
int felter[]={54619,48339,44260,44390,39732,44073,53308,35459,52448,38364,39990,47373};
//Added the waages of employees of all three companies to a 2-D array wages.
int wages[][]={alhermit,logway,felter};
InputStreamReader ir =new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(ir);
System.out.println("Enter the company for which would like employee salary statistics");
System.out.println("Enter 1 for Alhermit");
System.out.println("Enter 2 for Logway");
System.out.println("Enter 3 for Felter");
int id=Integer.parseInt(br.readLine());
double averageSalary=averageSalary(id,wages);
int employeeNo=employeeNumber(id,wages);
int totalSalary=totalSalary(id,wages);
System.out.println("Average salary of employees is "+averageSalary);
System.out.println("Total salary of employees is "+totalSalary);
System.out.println("Number of employees in the company are "+employeeNo);
}
//Method returns the average salary of all employees in a company
public static double averageSalary(int companyId,int wages[][])
{
int tSalary=totalSalary(companyId,wages);
int numEmployee=employeeNumber(companyId,wages);
double averageSalary=tSalary/numEmployee;
return averageSalary;
}
//Method returns the total of salaries of all employees in a company
public static int totalSalary(int companyId,int wages[][])
{
int total=0;
for(int i=0;i<wages[0].length;++i)
{
total+=wages[companyId-1][i];
}
return total;
}
//Static method for calculating the number of employees in the company
public static int employeeNumber(int companyId,int wages[][])
{
return wages[0].length;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.