8_6 Write a program (In java) that lets the user enter four quarterly sales figu
ID: 3626087 • Letter: 8
Question
8_6Write a program (In java) 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 decease 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.
The output may look like:
SALES AMOUNTS BY DIVISION
=========================
DIVISION 1
Quarter 1: $1000.0
Quarter 2: $2000.0
Quarter 3: $3000.0
Quarter 4: $4000.0
DIVISION 2
Quarter 1: $10000.0
Quarter 2: $20000.0
Quarter 3: $30000.0
Quarter 4: $40000.0
DIVISION 3
Quarter 1: $100000.0
Quarter 2: $200000.0
Quarter 3: $300000.0
Quarter 4: $400000.0
DIVISION 4
Quarter 1: $10000.0
Quarter 2: $20000.0
Quarter 3: $30000.0
Quarter 4: $40000.0
DIVISION 5
Quarter 1: $1000.0
Quarter 2: $2000.0
Quarter 3: $3000.0
Quarter 4: $4000.0
DIVISION 6
Quarter 1: $100.0
Quarter 2: $200.0
Quarter 3: $300.0
Quarter 4: $400.0
QUARTERLY INCREASE/DECREASE BY DIVISION
=======================================
DIVISION 1
Quarter 2's increase: $1000.0
Quarter 3's increase: $1000.0
Quarter 4's increase: $1000.0
DIVISION 2
Quarter 2's increase: $10000.0
Quarter 3's increase: $10000.0
Quarter 4's increase: $10000.0
DIVISION 3
Quarter 2's increase: $100000.0
Quarter 3's increase: $100000.0
Quarter 4's increase: $100000.0
DIVISION 4
Quarter 2's increase: $10000.0
Quarter 3's increase: $10000.0
Quarter 4's increase: $10000.0
DIVISION 5
Quarter 2's increase: $1000.0
Quarter 3's increase: $1000.0
Quarter 4's increase: $1000.0
DIVISION 6
Quarter 2's increase: $100.0
Quarter 3's increase: $100.0
Quarter 4's increase: $100.0
SALES AMOUNTS BY QUARTER
========================
Quarter 1: $122,100.00
Quarter 2: $244,200.00
Quarter 3: $366,300.00
Quarter 4: $488,400.00
QUARTERLY INCREASE/DECREASE FOR THE COMPANY
===========================================
Quarter 2: $122,100.00
Quarter 3: $122,100.00
Quarter 4: $122,100.00
AVERAGE SALES PER QUARTER
=========================
Quarter 1: $20,350.00
Quarter 2: $40,700.00
Quarter 3: $61,050.00
Quarter 4: $81,400.00
DIVISION WITH THE HIGHEST SALES PER QUARTER
===========================================
Highest division for quarter 1 is division 3
Highest division for quarter 2 is division 3
Highest division for quarter 3 is division 3
Highest division for quarter 4 is division 3
Explanation / Answer
please rate - thanks
import java.util.*;
import java.text.DecimalFormat;
import java.text.NumberFormat;
public class quarterlySales
{
public static void main(String args[])
{double sum[ ]=new double[4];
double sales[][] = new double[6][4];
NumberFormat formatter = new DecimalFormat("#,000.00");
getSales(sales);
printSales(sales,formatter);
quarterlyIncrease(sales,formatter);
quarterSales(sales,sum,formatter);
quarterSumIncrease(sum,formatter);
quarterAverage(sum,formatter);
highestDivision(sales);
}
public static void highestDivision(double sales[][])
{System.out.println(" DIVISION WITH THE HIGHEST SALES PER QUARTER ==================================");
int i,j,max=0;
double maxvalue;
for(i=0;i<4;i++)
{maxvalue=-1;
for(j=0;j<6;j++)
if(sales[j][i]>maxvalue)
{max=j;
maxvalue=sales[j][i];
}
System.out.println("Highest division for quarter "+(i+1)+" is division " + (max+1));
}
}
public static void quarterAverage(double sum[],NumberFormat f)
{System.out.println(" AVERAGE SALES PER QUARTER =============================");
for(int j=0;j<4;j++)
System.out.println("Quarter "+(j+1)+": $"+f.format(sum[j]/6.));
}
public static void quarterSumIncrease(double sum[],NumberFormat f)
{System.out.println(" QUARTERLY INCREASE/DECREASE FOR THE COMPANY ====================================");
for(int j=1;j<4;j++)
System.out.println("Quarter "+(j+1)+": $"+f.format(sum[j]-sum[j-1]));
}
public static void quarterSales(double sales[][],double sum[],NumberFormat f)
{System.out.println(" SALES AMOUNTS BY QUARTER ========================");
int i,j;
for(i=0;i<4;i++)
{sum[i]=0;
for(j=0;j<6;j++)
sum[i]+=sales[j][i];
}
for(j=0;j<4;j++)
System.out.println("Quarter "+(j+1)+": $"+f.format(sum[j]));
}
public static void quarterlyIncrease(double sales[][],NumberFormat f)
{System.out.println(" QUARTERLY INCREASE/DECREASE BY DIVISION ==============================");
for(int i=0;i<6;i++)
{System.out.println("Division "+(i+1));
for(int j=1;j<4;j++)
System.out.println("Quarter "+(j+1)+"'s increase: $"+f.format(sales[i][j]-sales[i][j-1]));
}
}
public static void printSales(double sales[][],NumberFormat f)
{System.out.println(" SALES AMOUNTS BY DIVISION =========================");
for(int i=0;i<6;i++)
{System.out.println("Division "+(i+1));
for(int j=0;j<4;j++)
System.out.println("Quarter "+(j+1)+": $"+f.format(sales[i][j]));
}
}
public static void getSales(double sales[][])
{
Scanner input = new Scanner(System.in);
int i,j;
for(i = 0; i < 6; i++)
for(j = 0; j < 4; j++)
{
System.out.print("Enter sales for quarter " + (j+1) + " for division " + (i+1) + ": ");
sales[i][j] = input.nextDouble();
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.