# One-Dimensional Array for Sales Commision

I have the following problem and have attached some code but you can see how lost I am with this probelm: Any help?

Use a one dimensional array to solve the following problem: A company pays its sales people on a commision basis.  The salespeope receive \$200 per week plus 9% of their gross sales for that week.  For example, a salesperson who grosses %5000 in sales in a week receives \$200 plus 9% of \$5000, or a total of \$650.

I need to write this using an array of counters that determines how many of the salepeople earned salaries in each of the following ranges (assume that each sales person's salary is truncated to an integer amount:
a. 200-299
b. 300-399
c. 400.499
d. 500-599
e. 600-699
f. 700-799
g. 800-899
h. 900-999
i. 1000 and over

Summarize the results in tabular format.
``````public class Sales
{
// counts the number of people in given salary ranges
public void countRanges()
{
// initialize the values in the array to zero

// read in values and assign them to the appropriate range

while ( dollars >= 0 )
{
//Calculate salary and ger range by salary / 100 ;

if ( range > 10 )
range = 10;

//count totals for every range

//Enter next sales amount (negative to end);
} // end while

// print chart
} // end method countRanges
} // end class Sales
``````
Java

Last Comment
spoxox

Offering more points because this will be easy for a Java Programmer and I need help quickly

I have this code now so I got the display the way I want it but now need  way to get the input to work.  If you run this, you can see it is all out of whack

``````public class Sales
{
public static void main( String args[] )
{
int array[] = { 500, 250, 650, 325, 575, 229, 979, 1200, 425, 875, 750 };

System.out.println( "Salary Statistics:" );
// for each array element, output a bar of the chart

for ( int counter = 2; counter < array.length; counter++ )

// output bar label ( "\$200-299: ", ...,"\$800-899: ", "\$900-999: ", "\$1000 and over: " )

if ( counter == 10 )
System.out.printf( "%5d and above: ", 1000 );
else
System.out.printf( "%02d-%02d: ",
counter * 100, counter * 100 + 99  );

// print bar of asterisks
for ( int stars = 0; stars < array[ counter ]; stars++ )
System.out.print( "*" );
System.out.println(); // start a new line of output
} // end outer for
} // end main
} // end class Sales
``````
atul_parmar

Hi,

From the information you provided, I understand that you want "how many of the salepeople earned salaries in each of the following ranges"

If so, try the following; I've commented the drawing of bars.

Atul

``````public class Sales
{
public static void main( String args[] )
{
int array[] = { 500, 250, 650, 325, 575, 229, 979, 1200, 425, 875, 750 };

System.out.println( "Salary Statistics:" );
// for each array element, output a bar of the chart

for ( int counter = 2; counter < array.length; counter++ ) {

// output bar label ( "\$200-299: ", ...,"\$800-899: ", "\$900-999: ", "\$1000 and over: " )
int counter1 = counter * 100;
int counter2 = counter1 + 99;
int noofsalesman = 0;
for (int i = 0; i < array.length; i++) {
if (array[i] >= counter1 && array[i] <= counter2)
noofsalesman++;
}
if ( counter == 10 )
System.out.printf( "%5d and above: %4d", 1000, noofsalesman);
else
System.out.printf( "%02d-%02d: %4d", counter1, counter2, noofsalesman);

// print bar of asterisks
/*for ( int stars = 0; stars < array[ counter ]; stars++ ) {
System.out.print( "*" );
}*/
System.out.println(); // start a new line of output
} // end outer for
} // end main
} // end class Sales
``````
spoxox

THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Java

Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.

102K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts

TRUSTED BY