Write a Java program to display the three top sales made by employees of an organization. The rows and columns represent the sales made by each employee identified by their employee number. SALES 1 SALES 2 SALES 3 101111 R 3 000 R 2 000 R 3 500 101122 R 2 500 R 5 500 R 3 500 101133 R 1 100 R 2 000 R 4 500 101144 R 1 700 R 2 700 R 2 500 101155 R 5 000 R 2 900 R 5 900 Using a Two Dimensional array produce the employee sales report, and the total sales made by each employee.
package employeesales;
public class EmployeeSales {
public static void main(String[] args) {
int [][] arr = new int[3][5];
int [] sales = {3000,2500,1100,1700,5000,2000,5500,2000,2700,2900,3500,3500,4500,2500,5900};
arr[0][0] = sales[0]; arr[1][0] = sales[5]; arr[2][0] = sales[10];
arr[0][1] = sales[1]; arr[1][1] = sales[6]; arr[2][1] = sales[11];
arr[0][2] = sales[2]; arr[1][2] = sales[7]; arr[2][2] = sales[12];
arr[0][3] = sales[3]; arr[1][3] = sales[8]; arr[2][3] = sales[13];
arr[0][4] = sales[4]; arr[1][4] = sales[9]; arr[2][4] = sales[14];
System.out.printf("Employees:\t101111\t\t101122\t\t101133\t\t101144\t\t101155\t\tTotal Sales\n");
int sum=0, total_sales = 0;
for(int i=0; i<3; i++){
System.out.printf("Sales%d:", (i+1));
for(int j=0; j<5; j++){
System.out.printf("\t\t%d", arr[i][j]);
sum +=arr[i][j];
}
total_sales +=sum;
System.out.println("\t\t"+sum);
sum = 0;
System.out.println();
}
int emp1 = arr[0][0] + arr[1][0] + arr[2][0] ;
int emp2 = arr[0][1]+arr[1][1] + arr[2][1] ;
int emp3= arr[0][2] + arr[1][2]+ arr[2][2];
int emp4= arr[0][3] + arr[1][3] + arr[2][3] ;
int emp5 = arr[0][4] + arr[1][4] + arr[2][4] ;
System.out.printf("Total:\t\t%d\t\t%d\t\t%d\t\t%d\t\t%d\t\t%d",emp1,emp2,emp3,emp4,emp5,total_sales );
}
}
Comments
Leave a comment