Problem:
Use a one-dimensional array to solve the following problem: A company pays its salespeople on a commission basis. The salespeople receive a $200 per week plus 9% of their gross sales for that week. For example, a salespeople 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):
Earned salaries:$200-$299
$300-$399
$400-$499
$500-$599
$600-$699
$700-$799
$800-$899
$900-$999
$1000 and over
Summarize the results in tabular format
Output:
Earned salaries: Gross sales:
$200-$299 $218-$226
$300-$399 $227-$235
$400-$499 $236-$244
$500-$599 $245-$253
$600-$699 $254-$262
$700-$799 $263-$271
$800-$899 $272-$280
$900-$999 $281-$289
$1000 and over $290 and over
$200-$299 $218-$226
$300-$399 $227-$235
$400-$499 $236-$244
$500-$599 $245-$253
$600-$699 $254-$262
$700-$799 $263-$271
$800-$899 $272-$280
$900-$999 $281-$289
$1000 and over $290 and over
Solution:
public class Problem { public static void main (String[] args) { int[] nums = new int[18]; System.out.println("Earned salaries: " + "\t" +"Gross sales: "); int a = 200; for (int i =0; i <18; i+=2) { nums[i] = a; nums[i+1] = a+99; a+=100; } for (int i =0; i <18; i+=2) { if ( i == 16) System.out.println("$"+nums[i] +"" +" and over" + "\t\t" +"$" + (int)(nums[i]*0.09 +200)+" "+"and over"); else System.out.println("$"+nums[i] +"-" +"$" + nums[i+1] +"\t\t" +"$" + (int)(nums[i]*0.09 +200)+"-"+"$" + (int)(nums[i+1]*0.09 +200)); } } }
No comments:
Post a Comment