Answer to Question #249467 in Java | JSP | JSF for khanyi

Question #249467

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-10T13:22:49-0400


public class App {


	public static void main(String[] args) {
		String[] months = { "DEVICE", "JAN", "FEB", "MAR", "TOTAL" };
		String[] devices = { "IPhone 7", "Samsung S8", "Huawei Mate 10" };
		int[][] sales = { { 30, 15, 35, 80 }, { 20, 25, 30, 75 }, { 25, 11, 32, 68 } };
		int[] total = { 75, 51, 97 };
		for (int i = 0; i < months.length; i++) {
			if (i == 0) {
				System.out.printf("%-17s ", months[i]);
			} else {
				System.out.printf("%-8s ", months[i]);
			}
		}
		System.out.println();
		for (int i = 0; i < sales.length; i++) {
			System.out.printf("%-17s ", devices[i]);
			for (int j = 0; j < sales[i].length; j++) {
				System.out.printf("%-8s ", sales[i][j]);
			}
			System.out.println();
		}


		System.out.printf("%-17s ", "MONTHLY TOTAL");
		for (int i = 0; i < total.length; i++) {
			System.out.printf("%-8s ", total[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