Question #248069

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.

Expert's answer



public class Main {


	public static void main(String[] args) {
		String[] salesNames = { "ID/SALE", "SALES 1", "SALES 2", "SALES 3", "TOTAL" };
		String[] employeeIDs = { "101111", "101122", "101133", "101144", "101155" };
		int[][] sales = { { 3000, 2000, 3500, 0 }, { 2500, 5500, 3500, 0 }, { 1100, 2000, 4500, 0 },
				{ 1700, 2700, 2500, 0 }, { 5000, 2900, 5900, 0 } };
		int[] salesTotal = { 0, 0, 0 };


		for (int i = 0; i < salesNames.length; i++) {
			if (i == 0) {
				System.out.printf("%-17s ", salesNames[i]);
			} else {
				System.out.printf("%-8s ", salesNames[i]);
			}
		}
		System.out.println();
		for (int i = 0; i < sales.length; i++) {
			System.out.printf("%-17s ", employeeIDs[i]);
			sales[i][3] = (sales[i][0] + sales[i][1] + sales[i][2]);
			salesTotal[0] += sales[i][0];
			salesTotal[1] += sales[i][1];
			salesTotal[2] += sales[i][2];
			for (int j = 0; j < sales[i].length; j++) {
				System.out.printf("%-8s ", sales[i][j]);
			}
			System.out.println();
		}


		
		System.out.println("\n\n******************************************");
		System.out.println("EMPLOYEES TOTAL SALES");
		System.out.println("******************************************");


		for (int i = 0; i < employeeIDs.length; i++) {
			System.out.printf("%-10sR%-5d\n", employeeIDs[i], sales[i][3]);
		}
	}
}
LATEST TUTORIALS
APPROVED BY CLIENTS