Q005 Sales Commission_program in java

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Q005 Sales Commission

Main.java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.println("Enter Details");
System.out.print("Sales Executive id: ");
int id = scanner.nextInt();
scanner.nextLine();
System.out.print("Name: ");
String name = scanner.nextLine();
System.out.print("Monthly sales amount: ");
double monthlySales = scanner.nextDouble();

SalesExecutive executive = new SalesExecutive(id, name, monthlySales);

System.out.println("Sales Executive Salary details");


System.out.printf("Sales Executive id: %d%n", executive.getId());
System.out.printf("Name: %s%n", executive.getName());
System.out.printf("Monthly sales amount: %.2f%n", executive.getMonthlySales());

float commissionPercentage = executive.calcComm();


if (commissionPercentage == 0.0f && monthlySales < 50000) {
System.out.println("Commission offered: Please provide justification for low sales");
System.out.printf("Fixed salary: %.2f%n", executive.getFixedSalary());
System.out.printf("Commission amount: %.2f%n", 0.0);
System.out.printf("Net salary: %.2f%n", executive.getFixedSalary());
} else {
System.out.printf("Commission offered: %.1f%%%n", commissionPercentage);
double commissionAmount = (commissionPercentage / 100) * monthlySales;
double netSalary = executive.getFixedSalary() + commissionAmount;
System.out.printf("Fixed salary Sales Executive: %.2f%n", executive.getFixedSalary());
System.out.printf("Sales Executive Commission amount: %.2f%n", commissionAmount);
System.out.printf("Net Amount Paid to Sales Executive: %.2f%n", netSalary);
}

scanner.close();
}
}

SalesExecutive.java
public class SalesExecutive {
private int id;
private String name;
private double monthlySales;
private static final double FIXED_SALARY = 10000.00;

public SalesExecutive(int id, String name, double monthlySales) {


this.id = id;
this.name = name;
this.monthlySales = monthlySales;
}

public float calcComm() {


if (monthlySales < 50000) {
return 0.0f;
} else if (monthlySales <= 100000) {
return 1.0f;
} else if (monthlySales <= 200000) {
return 2.5f;
} else if (monthlySales <= 300000) {
return 3.8f;
} else if (monthlySales <= 400000) {
return 4.2f;
} else {
return 5.5f;
}
}

public int getId() {


return id;
}

public String getName() {


return name;
}
public double getMonthlySales() {
return monthlySales;
}

public double getFixedSalary() {


return FIXED_SALARY;
}
}

Output:
Test Case 1:
Enter Details
Sales Executive id: 2001
Name: Ravi
Monthly sales amount: 80000.00
Sales Executive Salary details
Sales Executive id: 2001
Name: Ravi
Monthly sales amount: 80000.00
Commission offered:1.0%
Fixed salary Sales Executive: 10000.00
Sales Executive Commission amount: 800.00
Net Amount Paid to Sales Executive: 10800.00

Test Case 2:

Enter Details
Sales Executive id: 2003
Name: Tom
Monthly sales amount: 30000
Sales Executive Salary details
Sales Executive id: 2003
Name: Tom
Monthly sales amount: 30000.00
Commission offered: Please provide justification for low sales
Fixed salary: 10000.00
Commission amount: 0.00
Net salary: 10000.00

You might also like