Answer to Question #247478 in Java | JSP | JSF for Memo

Question #247478
Write a Java program to display three monthly sales of different vehicle types. The rows and
columns represent the monthly sales of each vehicle type.
JAN FEB MAR
SUV 25 15 35
COUPE 25 55 35
SEDAN 11 20 45
VAN 17 27 25
Using a Two-Dimensional array, produce the vehicle type sales report and the total sales made for
each vehicle type. If the total sales made per month are greater than or equal to 100, gold status
is awarded. If the monthly sales are less than 100, silver status is awarded.
1
Expert's answer
2021-10-06T11:46:13-0400


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)");
			}


		}
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS