Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Here is the problem: Write a program that will use a two-dimensional array to co

ID: 3539303 • Letter: H

Question

Here is the problem:

Write a program that will use a two-dimensional array to collect and store sales data for the ACME Widgets Company. ACME has sales offices in Boston, Chicago and Denver. You will need to have a method to allow/ask the user enter the sales data by quarter for each regional sales location, a method to display the sales data; and another method to calculate and display the total yearly sales for each region.

Your output should include the matrix (two-dimensional array) with all the data in place and the summary of yearly sales data.

Your display should resemble:


Part 2: Quarterly Sales Summary

Your output should resemble:

Here is what I have so far, I need help to get it to display correctly and to do all the summing on both outputs:

import java.util.*;

public class Acme {
public static void main (String[] args) {
Scanner input = new Scanner(System.in);

//array to collect sales data
int [][] sales = new int[3][4];
for (int row = 0; row < sales.length; row++){
System.out.print("Please enter the sales for your region: ");
for (int column = 0; column < sales[row].length; column++){
sales[row][column] = input.nextInt();
}
}
print(sales);
}
public static void print(int[][] sales){
String [][] region = {{"Boston", "Chicago", "Denver"},{"Quarter 1", "Quarter 2", "Quarter 3", "Quarter 4"}};

System.out.print(" " + " " + region[1][0] + " " + region[1][1] + " " + region[1][2] + " " + region[1][3] + " ");
System.out.println(region[0][0] + " ");
System.out.println(region[0][1]);
System.out.println(region[0][2]);
for (int row = 0; row < sales.length; row++){
for (int column = 0; column < sales[row].length; column++){
System.out.print(sales[row][column] + " ");
}
System.out.println();
}
}

}

Explanation / Answer

Image is not displayed


import java.util.*;


public class Mukesh

{

public static void main (String[] args)

{

Scanner input = new Scanner(System.in);

//array to collect sales data

int [][] sales = new int[3][4];

String[] region ={"Boston", "Chicago", "Denver"};

for(int i=0;i<3;i++)

{

for(int j=0;j<4;j++)

{

System.out.print("Enter the sales for quarter "+(j+1)+" for "+region[i]+": ");

sales[i][j]=input.nextInt();

}

}

print(sales,region);

}

public static void print(int[][] sales,String region[])

{

System.out.format("%5s", "Quarter ");

for(int i=1;i<=4;i++)

{

System.out.format("%5s", (i)+" ");

}

System.out.println();

for(int i=0;i<sales.length;i++)

{

System.out.print(region[i]+" ");

for(int j=0;j<sales[i].length;j++)

{

System.out.format("%5d",sales[i][j]);

}

System.out.println();

}

}


}