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

JAVA---Write a program that lets the user enter four quarterly sales figures for

ID: 3764182 • Letter: J

Question

JAVA---Write a program that lets the user enter four quarterly sales figures for six divisions of a company. The figures should be stored in a two-dimensional array. Once the figures are entered, the program should display the following data for each quarter:

• A list of the sales figures by division

• Each division’s increase or decrease from the previous quarter (this will not be displayed for the first quarter)

• The total sales for the quarter• The company’s increase or decrease from the previous quarter (this will not be displayed for the first quarter)

• The average sales for all divisions that quarter

• The division with the highest sales for that quarter

Input Validation: Do not accept negative numbers for sales figures.

Use basic programming loops, string and dialogbox.

Explanation / Answer

import java.util.*;
class quart_sale
{
   public static void main(String args[])
   {
       int[][] a=new int[4][6];
       int ii=0,i,as1=0,j,c=0,s=0,max;
       int p[] = new int[4];
       double av;
       Scanner o=new Scanner(System.in);

       for(i=0;i<4;i++)
       {
           System.out.println("Enter sales for quarter "+(i+1));
           for(j=0;j<6;j++)
           {
               a[i][j]=o.nextInt();
           }
       }
  
       System.out.println("Sales figure are");
       for(i=0;i<4;i++)
       {
           for(j=0;j<6;j++)
           {
               System.out.println(a[i][j]);
              
           }
       }

       for(i=0;i<4;i++)
       {
           for(j=0;j<6;j++)
           {
               s=s+a[i][j];
               as1=as1+a[i][j];
           }
           System.out.println("Total Sale for quarter "+(i+1)+ "is "+s);
           p[i]=s;
           s=0;
       }

       av=as1/4;

       System.out.println("Average sale for all Quarters is "+av);
       max=0;
       for(i=0;i<4;i++)
       {
           if(p[i]>max)
           {
               ii=i;
           }
       }
       System.out.println("Quarter with sale is "+(ii+1));      
   }
}