In Java Language: A sales person gets a base salary of $200. They also get 3% of
ID: 3905154 • Letter: I
Question
In Java Language: A sales person gets a base salary of $200. They also get 3% of any sales between 500 and $1000 and 5% of any sales over $1000 and under $3000 and 8% of anything $3000 or over. Write a driver program named Commission.java that takes in the amount of sales as input and outputs the total amount earned (the base salary plus commission). Make certain the output looks like money. Include a sentinel controlled loop that ends when you type in -999 for the sales. Also keep track of the total amount of money for all salespeople and how many total sales people there are (a counter and an accumulator).
NOTE: this is calculated like income tax is in the US. If a person sell $700, they get zero on the first 500 and 3% of the next 200 or $6.00 commission for a total salary of $206.00. If they sell $2500, they get zero on the first $500, 3% of the next 500, and 5% of anything over $1000.
Explanation / Answer
Commission.java
import java.util.Scanner;
public class Commission {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter the amount of sales:");
double sales = scan.nextDouble();
int count = 0;
int commissionRate;
double commission,accumulator=0;
while(sales != -999) {
count++;
commissionRate=0;
commission=200;
if(sales >=500 && sales<=1000) {
commissionRate=3;
} else if(sales>1000 && sales<3000){
commissionRate=5;
} else if(sales>=3000){
commissionRate=8;
}
commission =commission+ (sales * commissionRate)/100;
System.out.println("The total amount earned: "+commission);
accumulator+=commission;
System.out.println("Enter the amount of sales:");
sales = scan.nextDouble();
}
System.out.println("Accumulator: "+accumulator);
System.out.println("Total sales: "+count);
}
}
Output:
Enter the amount of sales:
800
The total amount earned: 224.0
Enter the amount of sales:
300
The total amount earned: 200.0
Enter the amount of sales:
1200
The total amount earned: 260.0
Enter the amount of sales:
3300
The total amount earned: 464.0
Enter the amount of sales:
-999
Accumulator: 1148.0
Total sales: 4
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.