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

Write a program that lets the user enter four quarterly sales figures for six di

ID: 3683329 • Letter: W

Question

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.

The profit/loss for each division from the previous quarter (1st Quarter is not displayed).

The total sales for each quarter

The profit/loss from the previous quarter (1st Quarter is not displayed).

The average sales for all divisions in each quarter.

The Division with the highest sale for each quarter.

Explanation / Answer

import java.util.*;
public class HelloWorld{

     public static void main(String []args){
        double sales[][]=new double[6][4];
         double totalSales[]=new double[6];
        System.out.println("Enter sales amount");
        Scanner read=new Scanner(System.in);
         double[] salesQuarter=new double[4];
                    double max=0;
        for(int i=0;i<6;i++)
        {
        for(int j=0;j<4;j++)
        sales[i][j]=read.nextDouble();
        System.out.println(" ");
        }
        for(int i=0;i<3;i++)
        {
        for(int j=0;j<4;j++)
         totalSales[i]+=sales[i][j];
        System.out.println("Total Sales of division "+i +" is: "+totalSales[i]);
        }

//print profit/loss for each diviosion
         for(int i=0;i<6;i++)
         {
         System.out.println("For Division "+i);
        for(int j=1;j<4;j++)
        {
         if(sales[i][j] > sales[i][j-1])
         System.out.println("Profit of Quarter "+j+" is "+((sales[i][j]-sales[i][j-1])*100)/sales[i][j-1]+"%");
        else
        System.out.println("Loss of Quarter "+j+" is "+((sales[i][j-1]-sales[i][j])*100)/sales[i][j-1]+"%");
        }
        }
       //print quarter sales
        for(int j=0;j<4;j++)
        {
        for(int i=0;i<6;i++)
        salesQuarter[j]+=sales[i][j];
        System.out.println("Sales for Quater "+j+" is: "+salesQuarter[j]);
        }
      
        //profit/loss for each quarter
         for(int j=1;j<4;j++)
         {
        if(salesQuarter[j] > salesQuarter[j-1])
         System.out.println("Profit of Quarter "+j+" is "+((salesQuarter[j]-salesQuarter[j-1])*100)/salesQuarter[j-1]+"%");
        else
        System.out.println("Loss of Quarter "+j+" is "+((salesQuarter[j-1]-salesQuarter[j])*100)/salesQuarter[j-1]+"%");
        }
      
        //average sales for each quarter
         for(int j=0;j<4;j++)
         {

         System.out.println("Average Sales of Quarter "+j+" is "+(salesQuarter[j]/2));
         if(salesQuarter[j]>max)
         max=salesQuarter[j];
        }

        //Diviison with highest Sale
         for(int j=0;j<4;j++)
         {
             int i=0;
             max=0.0;
             for(i=0;i<6;i++)
             {
                if(sales[j][i]>max)
                max=sales[j][i];
             }
         System.out.println("Highest sales for Quarter "+j+" is "+max+" belongs to Division "+i);
        }
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote