Use single subscripted array(s) to solve the following problem. A company pays i
ID: 3607649 • Letter: U
Question
Use single subscripted array(s) to solve the following problem. A company pays its sales people on a commission basis. The salespeople receive $200 per week plus 9 percent of their gross sales for that week. For example, a salesperson who grosses $3000 in sales in a week receives $200 plus 9% of $3000, or a total of $470. Design a program that determines how many of the salespeople earned salaries in each of the following ranges. $200-$299 $300-$399 $400-$499 $500-$599 $600-$699 $700-$799 $800-$899 $900-$999 $1000 and over You will need to declare two arrays, one to hold the salary range and the other to accumulate the count of salespeople in that range. When you have to check for a range you store either the lowest value in each range in the array and compare the salary to each of those values or you can store the highest value and compare to that. The only change will be the relational operator that you use for your comparison. Which ever configuration you decide to use should be duplicated in a parallel counter array so that when you determine which range the sales fit into you have the subscript for the counter array already determined. Your output should list the salary range and the number of salespeople in that range. Don't forget to include modules in your solution. Don't forget to include modules in your solution.
Explanation / Answer
Below is your code in java
SalesComm.java
import java.util.Scanner;
public class SalesComm {
private double salary;
public double getSalary(int gross_sales) {
double salary = ((gross_sales * 0.09) + 200);
return salary;
}
public void displayMessage(int counter_array[]) {
System.out.println(" $200-299:"+counter_array[0]);
System.out.println(" $300-399: "+counter_array[1]);
System.out.println(" $400-499: "+counter_array[2]);
System.out.println(" $500-599; "+counter_array[3]);
System.out.println(" $600-699: "+counter_array[4]);
System.out.println(" $700-799: "+counter_array[5]);
System.out.println(" $800-899: "+counter_array[6]);
System.out.println(" $900-999: "+counter_array[7]);
System.out.println(" $1000 and over: "+counter_array[8]);
}
public void increaseArray(double salary, int counter_array[]) {
if (salary >= 1000.00) {
counter_array[8]++;
} else if (salary >= 900.00) {
counter_array[7]++;
} else if (salary >= 800.00) {
counter_array[6]++;
} else if (salary >= 700.00) {
counter_array[5]++;
} else if (salary >= 600.00) {
counter_array[4]++;
} else if (salary >= 500.00) {
counter_array[3]++;
} else if (salary >= 400.00) {
counter_array[2]++;
} else if (salary >= 300.00) {
counter_array[1]++;
} else if (salary >= 200.00) {
counter_array[0]++;
}
}
public void salesMethod() {
int counter_array[] = new int[9];
int gross_sales;
double salary = 0.0;
Scanner input = new Scanner(System.in);
System.out.printf("Enter sales amount (Negative to end) ");
gross_sales = input.nextInt();
while (gross_sales >= 0) {
salary = getSalary(gross_sales);
increaseArray(salary, counter_array);
System.out.printf("Enter sales amount (Negative to end) ");
gross_sales = input.nextInt();
}
displayMessage(counter_array);
}
public static void main(String[] args) {
SalesComm sc = new SalesComm();
sc.salesMethod();
}
}
Output
Enter sales amount (Negative to end) 3000
Enter sales amount (Negative to end) 3200
Enter sales amount (Negative to end) 5600
Enter sales amount (Negative to end) 91000
Enter sales amount (Negative to end) 22
Enter sales amount (Negative to end) 3040
Enter sales amount (Negative to end) -1
$200-299:1
$300-399: 0
$400-499: 3
$500-599; 0
$600-699: 0
$700-799: 1
$800-899: 0
$900-999: 0
$1000 and over: 1
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.