Create the project then add the classes for the application that allows users to
ID: 665547 • Letter: C
Question
Create the project then add the classes for the application that allows users to calculate the salary of vendors who get monthly base salary plus commission and bonus based on the sale amount.
The commission, bonus are calculated by applying the following rule:
RULE
Commission
Bonus
Vendor sell up to $27000 worth of items per month to get base salary only
0
0
When Sale amount is greater than $27,000
8% on extra sales
0
When Sale amount is greater than $35,000
8% on extra sales
4% on top of normal commission for any sales beyond $35000
For example: if the base salary is $2000.0
if sale amount is $24000, then vendor only gets the base salary
commission = 0
bonus = 0
salary = $2000
If sale amount is $30,000, then vendor can get the base salary and the commission:
commission = 8 % of ($30000 - $27000) = 0.08 * 3000 = 240
bonus = 0
salary = 2000 + 240 = $2240.00
If sale amount is $42000, then vendor can get the base salary, the commission and the bonus
commission = 8 % of (42000 - 25000) = 0.08 * 17000 = 1360
bonus = 4% of (42000 - 35000) = 0.04 * 7000 = 280
salary = 2000 + 1360 + 280 = 3640
The total of salary is calculate by the formula:
Total of salary = base salary + commission + bonus
Where base salary is input from the keyboard
HOW TO DO THE LAB:
Create the project then add two classes named as class SU15LAB4_LastName_SalaryOfVendor and class VendorInfo_LastName
Class VendorInfo_LastName: maintain vendor name (String), id (String), base salary (double), and sale amount (double) and include the following:
-no-argument constructor and parameter constructor
-all methods that calculate the commission, bonus and total of salary of the vendor
*The vendors have the sale up to $27000 to get the base salary only
*If the sale amount is greater than $27000, the vendor can get 8% on extra sale for commission.
*if the total sale of items is greater than $35000, besides getting 8% for commission, the vendor can get bonus 4% more on top of the commission for any sales beyond 35000.
-method toString to print out the result in the following format
………………………………………………………….
Vendor Name: Smith Crystal
Vendor ID: 12345
Total sale: $38128
Base Salary: $2000
Commission: $890.24
Bonus: $125.12
Total Amount made: $3015.36
……………………………………………………………
Class SP15LAB4_LastName_SalaryOfVendor: this is the controlling class or driver class that contains main()
-Read information from the keyboard: vendor name (String), id (String), base salary (double), and sale amount (double)
-create the object of class VendorInfo_LastName to pass all input information to the objec
-print out the result as requested format by calling the method toString
RULE
Commission
Bonus
Vendor sell up to $27000 worth of items per month to get base salary only
0
0
When Sale amount is greater than $27,000
8% on extra sales
0
When Sale amount is greater than $35,000
8% on extra sales
4% on top of normal commission for any sales beyond $35000
Explanation / Answer
/*The class VendorInfo_LastName that has no argument and parameterized consturctors.
* The class also contains methods to calculates the commission, bonus and total salary.
* The method toString that returns the string represenation of vendor information*/
//VendorInfo_LastName.java
public class VendorInfo_LastName
{
//private members of the class
private String vendorName;
private int id;
private double baseSalary;
private double saleAmount;
//No-argument constructor
public VendorInfo_LastName()
{
vendorName="";
id=0;
baseSalary=0;
saleAmount=0;
}
//Parameterised constructor
public VendorInfo_LastName(String vendorName,
int id,
double baseSalary,
double saleAmount)
{
this.vendorName=vendorName;
this.id=id;
this.baseSalary=baseSalary;
this.saleAmount=saleAmount;
}
/*The method calculates the commission on salary which is greater than 27000 then
* 8 % extra
* */
public double getCommission()
{
double commission=0;
if(saleAmount>27000)
commission= (saleAmount-27000)*0.08;
else
commission=0;
return commission;
}
/*The method calculates the bonus on salary which is greater than 35000 then
* 4 % extra
* */
public double getBonus()
{
double bonus=0;
if(saleAmount>35000)
bonus= (saleAmount-35000)*0.04;
else
return bonus=0;
return bonus;
}
/*The method calculates the total salary */
public double getTotalSalary()
{
return baseSalary+getCommission()+getBonus();
}
/*Returns the string representaion of vendor information*/
@Override
public String toString()
{
String strDesc;
strDesc=String.format("Vendor Name : %s " +
"Vendor ID : $%d " +
"Total sale : $%-10.2f " +
"Base Salary : $%-10.2f "+
"Commission : $%-10.2f "+
"Bonus : $%-10.2f "+
"Total Amount made : $%-10.2f "
,
vendorName,id,saleAmount,baseSalary,getCommission(),getBonus(),getTotalSalary());
//return string strDesc
return strDesc;
}
}
-------------------------------------------------------------------------------------------------------------------------------------------------
//Driver class to test the method that prompts the user to enter the name of vender, id number, base salary
//and total sales .Then calculates the commission ,bonus and total salary and prints as string representation
//SU15LAB4_LastName_SalaryOfVendor.java
import java.util.Scanner;
public class SU15LAB4_LastName_SalaryOfVendor
{
public static void main(String[] args)
{
//Create an instance of Scanner class
Scanner scanner=new Scanner(System.in);
String vendorName;
int id;
double baseSalary;
double saleAmount;
System.out.println("Enter vendor name : ");
//prompt for vendor name
vendorName=scanner.nextLine();
System.out.println("Enter vendor id : ");
//prompt for vendor id
id=scanner.nextInt();
System.out.println("Enter base salary : ");
//prompt for base salary
baseSalary=scanner.nextDouble();
System.out.println("Enter sale amount : ");
//prompt for sale amount
saleAmount=scanner.nextDouble();
//Create an instance of class VendorInfo_LastName with name,id ,base salary and sales amount
VendorInfo_LastName vendor=
new VendorInfo_LastName(vendorName, id, baseSalary, saleAmount);
//print the information as string value
System.out.println(vendor.toString());
}
}
------------------------------------------------------------------------------------------------------------------------------
Sample output:
Enter vendor name :
Smith Crystal
Enter vendor id :
12345
Enter base salary :
2000
Enter sale amount :
38128
Vendor Name : Smith Crystal
Vendor ID : $12345
Total sale : $38128.00
Base Salary : $2000.00
Commission : $890.24
Bonus : $125.12
Total Amount made : $3015.36
Hope this helps you