In: Computer Science
A corporation has two divisions, each responsible for sales to different geographic locations. Design a DivSales class that keeps sales data for a division, with the following members: • An array with two elements for holding two halves of sales figures for the division. • A private static variable for holding the total corporate sales for all divisions for the entire year. • A member function that takes two arguments, each assumed to be the sales for a half year. The value of the arguments should be copied into the array that holds the sales data. The total of the two arguments should be added to the static variable that holds the total yearly corporate sales. • A function that takes an integer argument within the range of 0 to 1. The argument is to be used as a subscript into the division half-yearly sales array. The function should return the value of the array element with that subscript. Write a program that creates an array of two DivSales objects. The program should ask the user to enter the sales for two half-year for each division. After the data is entered, the program should display a table showing the division sales for each half-year. The program should then display the total corporate sales for the year.
Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
_________________
// DivSales.java
public class DivSales {
private int sales[];
private static int totalCorporateSales=0;
public DivSales() {
sales = new int[2];
}
public void readSalesData(int num1, int num2)
{
sales[0] = num1;
sales[1] = num2;
totalCorporateSales += sales[0] +
sales[1];
}
public int getHalfYearSalesData(int indx) {
return sales[indx];
}
public static int getTotalCorporateSales()
{
return totalCorporateSales;
}
}
___________________________
// Test.java
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
DivSales arr[]=new
DivSales[2];
/*
* Creating an Scanner class object
which is used to get the inputs
* entered by the user
*/
Scanner sc = new
Scanner(System.in);
int sales1,sales2;
for(int
i=0;i<arr.length;i++)
{
System.out.print("Enter division "+(i+1)+" sales of
first half year :$");
sales1=sc.nextInt();
System.out.print("Enter division "+(i+1)+" sales of
second half year :$");
sales2=sc.nextInt();
arr[i]=new DivSales();
arr[i].readSalesData(sales1,sales2);
}
for(int
i=0;i<arr.length;i++)
{
System.out.print("Division#"+(i+1)+"
Sales:"+arr[i].getHalfYearSalesData(0)+"\t"+arr[i].getHalfYearSalesData(1)+"\n");
}
System.out.println("Total Corporate
Sales :$"+DivSales.getTotalCorporateSales());
}
}
______________________________
Output:
Enter division 1 sales of first half year
:$4500
Enter division 1 sales of second half year :$6500
Enter division 2 sales of first half year :$2300
Enter division 2 sales of second half year :$7800
Division#1 Sales:4500 6500
Division#2 Sales:2300 7800
Total Corporate Sales :$21100
_______________Could you plz rate me well.Thank
You