Java2 codes,problems ,discussions and solutions are here
Sat Jun 23, 2007 1:21 pm
The following file has the problem and the solution, however I can getting the following error "cannot find symbol variable math" when compiling. Where am I going wrong at?
Bama
(Sales Commissions) Use a one-dimensional array to solve the following problem: A company pays its salespeople on a commission basis. The salespeople 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. Write an application (using an array of counters) that determines how many of the salespeople earned salaries in each of the following ranges (assume that each salesperson's salary is truncated to an integer amount):
1. $200-299
2. $300-399
3. $400-499
4. $500-599
5. $600-699
6. $700-799
7. $800-899
8. $ 900-999
9. $1000 and over
Summarize the results in tabular format
- Code:
// Determining how many sales person earn salaries
public class Salary
{
public static void main (String args [])
{
// intializer list specifies the integers amount
double salary [] = { 0, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200};
int value []= new int [11];
System.out.printf( "%s:%20s:\n", "Index", " Value"); // column heading
for (int index = 0; index < (salary.length); index++)
{
if (10<=(int)math.floor(((salary[index]*(.9)+200)*.01)))
++value[10];
else
++value[(int)math.floor(((salary [index]* (.9)+200)*.01))];
}
for (int index1 =2; index1<value.length-1; index1++)
System.out.printf("$%5d-%5d: %10d\n",
index1 *100,index1 * 100 + 99, value[index1]);
// output each salary element's value.
for (int index2 =11; index2<= value.length; index2++ )
System.out.printf( "$%5d%5s: 20d\n", index2*100-100, "& more", value[10]);
} // end main
} // end class Salary
Sat Jun 23, 2007 1:51 pm
Hi bama,
The class name is
Math not math .I don't know why you post it twice
.
Sat Jun 23, 2007 3:19 pm
Sorry, I miss understood the first time. I know exactly what you meant. It compiled and executed. One other question, do you know of a way to check to see if the output is correct? Bama
Sun Jun 24, 2007 8:16 pm
What you mean by that "bama" .
.Please explain more .
Mon Jun 25, 2007 5:08 pm
My program did compile and it executed but my question is this. How do I know for sure if my output is correct? For example in math when you multiply 4 x 5 = 20, to check it, you divide 20 / 5 = 4. So is there a way I can see if my output is correct?
Mon Jun 25, 2007 5:18 pm
As i understood .
You see the output of your program and then see if it is the output which your program should do.
For example here in your program the output is :
Index: Value:
$ 200- 299: 1
$ 300- 399: 1
$ 400- 499: 1
$ 500- 599: 1
$ 600- 699: 1
$ 700- 799: 1
$ 800- 899: 1
$ 900- 999: 1
$ 1000& more: 20d
Mon Jun 25, 2007 5:52 pm
Yes I can see my output, however is it correct. I have nothing to compare it to. Also what do you you mean with "walking beside you and be your friend"?
Mon Jun 25, 2007 5:56 pm
it is my signature.
Mon Jun 25, 2007 6:12 pm
Oh, I see.
So do you understand my question now? Does it needs more work in your opinion?
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.