Commission Calculator Code Help for JAVA American Veeblefetz
Commission Calculator Code Help for JAVA
American Veeblefetzer, Inc. is a multinational distribution company. Each month it pays its sales force according to a formula that uses the employee\'s monthly sales, number of years with the company, and rank.
For sales amounts between $100,000 and $200,000 inclusive, the sales commission is 1% of sales. For amounts over $200,000 and up to $300,000, 1.5%. For amounts over $300,000 and up to $400,000, 1.75%. For amounts over $400,000, 2%.
These percentages are based on the total sales and not just on the incremental amounts.
(Note that although there is no sales commission if the amount sold is below $100K, the salesperson is still eligible for the other commissions.)
Each salesperson also receives a commission of 1/10 of 1% of sales for each year with the company, up to a maximum of 1% at 10 years or more.
Salespersons also have a rank of Apprentice, Junior, or Senior. Apprentices receive no rank incentive, while Juniors receive 0.1% of sales and Seniors 0.2%.
Write a CommissionCalculator class to compute the monthly commission earned by a salesperson, given the salesperson\'s name, total sales, years of service with the company, and rank. Also write a class to test your CommissionCalculator class.
Specifications:
Your test class will perform the following operations in the order listed:
1. Prompt the program user for the salesperson’s name, monthly sales, years of service, and rank code, and create an object using the data entered.
2. Call the method that returns the data entered and print the string returned.
3. Call the method that computes and returns the commission and print it, formatted as U.S. currency.
Solution
Please find the required program and output below: Please find the comments against each line for the description:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class Test
{
public static void main(String[] args) throws IOException
{
//Read the user input data
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(\"Enter salesperson’s name:\");
String name = br.readLine();
System.out.println(\"Enter monthly sales:\");
int sales = Integer.parseInt(br.readLine());
System.out.println(\"Enter years of service:\");
int years = Integer.parseInt(br.readLine());
System.out.println(\"Enter salesperson’s rank:\");
String rank = br.readLine();
//create the CommissionCalculator object based on user inputs
CommissionCalculator cc = new CommissionCalculator(name, sales, years, rank);
//get the commission
double commission = cc.calculateCommission();
//print the commission
System.out.println(\"Total Commission = $\"+commission);
}
}
class CommissionCalculator {
String name;
int sales;
int years;
String rank;
public CommissionCalculator(String name, int sales, int years, String rank) {
this.name = name;
this.sales = sales;
this.years = years;
this.rank = rank;
}
public double calculateCommission(){
double p = 0;
//calculate the percentage of commission based on sales
if(sales>=100000 && sales<=200000){
p = 1;
}else if(sales>200000 && sales<=300000){
p = 1.5;
}else if(sales>300000 && sales<=400000){
p = 1.75;
}else if(sales>400000){
p = 2;
}
double amt = (p/100)*sales;
//calculate the percentage of commission based on years of experience in company
if(years<=10)
amt = amt + (years/10)*((1/100)*sales);
else
amt = amt + ((1/100)*sales);
//calculate the percentage of commission based on rank
if(rank.equalsIgnoreCase(\"junior\")){
amt = amt + ((0.1/100)*sales);
}else{
amt = amt + ((0.2/100)*sales);
}
return amt;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getSales() {
return sales;
}
public void setSales(int sales) {
this.sales = sales;
}
public int getYears() {
return years;
}
public void setYears(int years) {
this.years = years;
}
public String getRank() {
return rank;
}
public void setRank(String rank) {
this.rank = rank;
}
}
-----------------------------------------
OUTPUT:
Enter salesperson’s name:
Christo
Enter monthly sales:
340000
Enter years of service:
8
Enter salesperson’s rank:
junior
Total Commission = $6290.00


