Question

In: Computer Science

Loop and Function You are asked to develop a compensation calculator application for a department store....

Loop and Function

You are asked to develop a compensation calculator application for a department store. At the department store, the compensation of sales staff consists of a base salary and a commission. The base salary is $5,000, and the commission rate is tiered based on sales amount as following:

Sales Amount, commission rate
$0.01 – $5,000, 8%

$5,000.01 – $10,000, 10%

$10,000.01 and above, 12%

For example, if the sales amount is $12,000, the commission is calculated as following: commission = $5,000 * 8% +

($10,000 - $5,000) * 10% + ($12,000 - $10,000) * 12%. You can start with a few specific amounts first to help you figure out the general representation for commission calculation.

Requirements: (1) Define compute_commission function that computes the commission, using the above commission scheme. This function receives one parameter representing the sales amount and returns the corresponding commission.

(2) Define a print_commission function, which receives three parameters representing the beginning sales amount, sales increment, and ending sales amounts, and has no return. This function uses a for-loop to display a sales and commission table. For example, if the beginning sales amount is 10000, sales increment is 5000, and the ending sales amount is 100000, then this function will print out the following table:

Sales Amount | commission

10000 | 900.00
15000  | 1500.00

...

95000. | 11100.00

100000. | 11700.00
Note: this function must call the compute_commission function to determine the commission column.

(3) Next, define a target_sales function, which receives one parameter representing a desired salary and returns the corresponding sales amount that generates the desired salary. For example, if a staff’s desired salary is 30000 (which consists of base salary + commission), then this function will return a sales amount of 210834, which is the minimum sales amount that the staff must generate to earn the desired 30000 salaries. Note: this function must use a while-loop, and it must call the compute_commission function whenever you want to calculate the commission. In addition, it must start with an initial sales amount of $1 and increases the sales amount only by $1 in each iteration until it finds the sales amount needed to generate the desired salary.

(4) Define the main function, which will call the print_commission function to display a sales-commission table with 10000 as the beginning sales amount, 5000 as the sales increment, and 100000 as the ending sales amount. Then, ask users to enter their desired salary and use it as the argument to call the target_sales function. Lastly, display a message informing user the sales amount needed for the desired salary.

(5) Call the main function. Fix any syntax errors and test your code if you can.

Solutions

Expert Solution

import java.io.*
import java.util.Scanner;
public class CommissionCalculator {
public static double computeCommission(double sales) {
if(sales <= 5000) {
return sales * 0.08;
} else if(sales <= 10000) {
return 5000 * 0.08 + (sales - 5000)*0.1;
} else {
return 5000 * 0.08 + 5000 * 0.1 + (sales - 10000)*0.12;
}
}
public static void printCommission (double beginningSalesAmount, double salesIncrement, double endingSalesAmount)
{
System.out.println("Sales Amount\tCommission Rate");
for(double amount=beginningSalesAmount; amount <= endingSalesAmount; amount += salesIncrement) 
{
System.out.printf("%.0f\t%.1f\n",amount, computeCommission(amount));
}
}
public static double targetSales(double desiredSalary) {
//base salary reduce
double remainingSalary = desiredSalary - 5000;
double salesAmount = 0.01;
while(computeCommission(salesAmount) < remainingSalary) {
salesAmount += 0.01;
}
return salesAmount;
}
public static void main(String[] args) {
printCommission(10000, 5000, 100000);
Scanner keyboard = new Scanner(System.in);
System.out.println("\nEnter your desired salary: $");
double desired = keyboard.nextDouble();
System.out.printf("You need to generate sales amount: $%.2f", targetSales(desired));
keyboard.close();
}
}

Related Solutions

Homework 3 Loop and Function (PYTHON) You are asked to develop a compensation calculator application for...
Homework 3 Loop and Function (PYTHON) You are asked to develop a compensation calculator application for a department store. At the department store, the compensation of sales staff consists of a base salary and a commission. The base salary is $5,000, and the commission rate is tiered based on sales amount as following: Sales AmountCommission Rate $0.01 – $5,000 8% $5,000.01 – $10,000 10% $10,000.01 and above12% For example, if the sales amount is $12,000, the commission is calculated as...
IHE Profiles If you are working in the IS department and were asked to develop interoperability...
IHE Profiles If you are working in the IS department and were asked to develop interoperability between two applications, why might you want to use IHE profiles? Have you had any situations where you had been asked to help with an interoperability initiative and wondered how you would start - this can be a situation in healthcare or not, IT or not. How did you get started?
Develop a Java application which implements an application for a store chain that has three types...
Develop a Java application which implements an application for a store chain that has three types of stores which are Book, Music, and Movie stores. Your application should have an Item abstract class which should be extended by the Book and Multimedia classes. Item class has abstract priceAfterTax method, you need to implement this method in derived classes. Multimedia class is a superclass for Music and Movie classes. Your project should also include the IPromotion interface, which should be implemented...
C++ Programming Enum - Structure - Array You are asked to develop software for HR department...
C++ Programming Enum - Structure - Array You are asked to develop software for HR department to calculate employee’s weekly salary. The program should contain the following information about a student by declaring a struct: Name (string of characters)        Employee ID (string of characters)        Level (ENGINEER, MANGER, DIRECTOR)        Hourly Rate (floating-point number)        Working Hours (floating-point number)        Weekly Salary (floating-point number) Your program will read an employee data and print the information of employee’s Name, Employee...
Plot the function without using a calculator, as you will not have a calculator on the...
Plot the function without using a calculator, as you will not have a calculator on the exams. a. ? = 34 sin ?, from t = 0 to the end of the first cycle only. b. ? = 2sin3?, from t = 0 to the end of the second cycle only. c. ? = 2cos3?, from t = 0 to the end of the second cycle only. d. ? = 2sin??, from t = 0 to the end of the...
You were asked to investigate extreme high, unexplained merchandise shortages at a department store chain. You...
You were asked to investigate extreme high, unexplained merchandise shortages at a department store chain. You found the following: The receiving department supervisor owns and operates a boutique carrying many of the same labels as the chain store. The general manager is unaware of the ownership interest. The receiving supervisor signs receiving reports showing that the total quantity shipped by a supplier was received and then diverts 5% to 10 % of each shipment to the boutique. The store is...
The Application Analyst (AA) department manager, Lori Williams, called the training department and asked to sit...
The Application Analyst (AA) department manager, Lori Williams, called the training department and asked to sit down and discuss the new product they were rolling out to all the company's AAs, worldwide, and what training could be offered starting on August 11 and ongoing as they were looking to roll out Document Manager on October 2. This product would affect 2500 people. Lori Williams met with two trainers, Sarah Ward and Caroline Smith. Lori explained that all of the AAs...
Develop a python program that will determine if a department store customer has exceeded the credit...
Develop a python program that will determine if a department store customer has exceeded the credit limit on a charge account. For each customer, the following facts are available:  Account number  Balance at the beginning of the month  Total of all items charged by this customer this month  Total of all credits applied to this customer’s account this month  Allowed credit limit The program should input each of the facts, calculate the new balance (=beginning...
Develop a python program that will determine if a department store customer has exceeded the credit...
Develop a python program that will determine if a department store customer has exceeded the credit limit on a charge account. For each customer, the following facts are available:  Account number, Balance at the beginning of the month, Total of all items charged by this customer this month, Total of all credits applied to this customer’s account this month and Allowed credit limit. The program should input each of the facts, calculate the new balance (=beginning balance + charges – credits),...
. A quality survey asked recent customers of their experience at a local department store. One...
. A quality survey asked recent customers of their experience at a local department store. One question asked for the customers rating on their service using categorical responses of average, outstanding, and exceptional. Another question asked for the applicant’s education level with categorical responses of Some HS, HS Grad, Some College, and College Grad. The sample data below are for 700 customers who recently visited the department store. Education Quality Rating Some HS HS Grad Some College College Grad Average...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT