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

Question #247473
Write a Java program that will create a report to display the top three mobile device sales per month
from January to March 2018. The rows and columns represent the monthly sales of each device.
JAN FEB MAR TOTAL
IPhone 7 30 15 35 80
Samsung S8 20 25 30 75
Huawei Mate 10 25 11 32 68
MONTHLY TOTAL 75 51 97
Using a Two-Dimensional array, produce the monthly mobile device sales report and the total sales
for each device.
1
Expert's answer
2021-10-06T11:46:16-0400




public class Main {


	public static void main(String[] args) {
		String[] monthsNames = { "DEVICE", "JAN", "FEB", "MAR", "TOTAL" };
		String[] deviceNames = { "IPhone 7", "Samsung S8", "Huawei Mate 10" };
		int[][] monthlySales = { { 30, 15, 35, 80 }, { 20, 25, 30, 75 }, { 25, 11, 32, 68 } };
		int[] monthlyTotal = { 75, 51, 97 };
		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]);
			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]);
		}
	}
}

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