public class Main {
public static void main(String[] args) {
String[] monthsNames = { "Vehicle", "JAN", "FEB", "MAR", "TOTAL" };
String[] deviceNames = { "SUV", "COUPE", "SEDAN", "VAN" };
int[][] monthlySales = { { 25, 15, 35, 0 }, { 25, 55, 35, 0 }, { 11, 20, 45, 0 }, { 17, 27, 25, 0 } };
int[] monthlyTotal = { 0, 0, 0 };
for (int i = 0; i < monthsNames.length; i++) {
if (i == 0) {
System.out.printf("%-17s ", monthsNames[i]);
} else {
System.out.printf("%-8s ", monthsNames[i]);
}
}
System.out.println();
for (int i = 0; i < monthlySales.length; i++) {
System.out.printf("%-17s ", deviceNames[i]);
monthlySales[i][3] = (monthlySales[i][0] + monthlySales[i][1] + monthlySales[i][2]);
monthlyTotal[0] += monthlySales[i][0];
monthlyTotal[1] += monthlySales[i][1];
monthlyTotal[2] += monthlySales[i][2];
for (int j = 0; j < monthlySales[i].length; j++) {
System.out.printf("%-8s ", monthlySales[i][j]);
}
System.out.println();
}
System.out.printf("%-17s ", "MONTHLY TOTAL");
for (int i = 0; i < monthlyTotal.length; i++) {
System.out.printf("%-8s ", monthlyTotal[i]);
}
System.out.println("\n\n******************************************");
System.out.println("VEHILE TOTAL SALES");
System.out.println("******************************************");
for (int i = 0; i < deviceNames.length; i++) {
if (monthlySales[i][3] >= 100) {
System.out.printf("%-10s%-5d%-5s\n", deviceNames[i], monthlySales[i][3], "(Gold Star)");
} else {
System.out.printf("%-10s%-5d%-5s\n", deviceNames[i], monthlySales[i][3], "(Silver Star)");
}
}
}
}
Comments
Leave a comment