Java program to calculate salesperson commission. The following program has been written in five different ways like using standard values, Taking inputs through scanner class, using command line arguments, user-defined method, creating a separate class. The following code can be used in any different manner, for salesperson, java code sales commission calculator, simple commission calculation program part 2.
- How to calculate commission rate?
Multiply your commission rate by your commission base for the period to calculate your commission payment.
Example :
For example, if you made $30,000 worth of sales from March 1 to March 15 and your commission rate is 5 per cent, your commission payment is $1,500
1. Java Program To Calculate Commission Using Standard Values
There you go the following program is written based on a formula, consider this as a standard program. You can use this program anywhere like Java salesperson commission, commission calculator. #java salesperson commission
1 2 3 4 5 6 7 8 9 10 11 |
class CalculateCommission { public static void main(String arg[]) { double amount=1000,commissionPercentage=15; double commission=(commissionPercentage/100)*amount; System.out.println("Commission amount="+commission); } } |
output:
1 |
Commission amount =150.0 |
2. Taking Inputs Through Scanner Class
Java code for obtaining commission percentage taking inputs through scanner class, Java salesperson commission and, simple commission calculation program part 2.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
java.util.Scanner; class CalculateCommission { public static void main(String arg[]) { Scanner sc=new Scanner(System.in); System.out.print("Enter amount:"); double amount=sc.nextDouble(); System.out.print("Enter commissionPercentage:"); double commissionPercentage=sc.nextDouble(); double commission=(commissionPercentage/100)*amount; System.out.println("Commission amount="+commission); } } |
output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
Output:1 Enter amount: 100000 Enter commissionPercentage: 10 Commission amount = 10000.0 Output:2 Enter amount:25000 Enter commissionPercentage:25 Commission amount=6250.0 |
3. Through Command Line Arguments
There you go another method by using command line arguments. If you no idea about command line arguments you can check out the guide here on how to command line arguments works #simple commission calculation program part 2.
Learn more :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
java.util.Scanner; class CalculateCommission { public static void main(String args[]) { double amount=Double.parseDouble(args[0]); double commissionPercentage=Double.parseDouble(args[1]); double commission=(commissionPercentage/100)*amount; System.out.println("Commission amount="+commission); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
Output:1 C:\Users\goutham\Desktop\E>javac CalculateCommission.java C:\Users\goutham\Desktop\E>java CalculateCommission 1000 10 Commission amount=100.0 Output:2 C:\Users\goutham\Desktop\E>javac CalculateCommission.java C:\Users\goutham\Desktop\E>java CalculateCommission 20000 25 Commission amount=5000.0 |
4. User Define Method
By using a user-defined method we wrote the following program to calculate commission percentage program.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
java.util.Scanner; class CalculateCommission { public static void main(String arg[]) { Scanner sc=new Scanner(System.in); System.out.print("Enter amount:"); double amount=sc.nextDouble(); System.out.print("Enter commissionPercentage:"); double commissionPercentage=sc.nextDouble(); double commission=calculateCommission(amount , commissionPercentage); System.out.println("Commission amount="+commission); } static double calculateCommission(double x, double y) { return (y/100)*x; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
Output:1 Enter amount:1000 Enter commissionPercentage:17.55 Commission amount=175.50000000000003 Output:2 Enter amount:15500 Enter commissionPercentage:50 Commission amount=7750.0 |
5. Creating Separate Class
Java program for getting commission percentage through creating a separate class( ) and taking inputs through scanner class. #java code sales commission calculator #simple commission calculation program part 2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
java.util.Scanner; class Calculate { double res; Calculate(double x, double y) { res=(y/100)*x; } } class CalculateCommission { public static void main(String arg[]) { Scanner sc=new Scanner(System.in); System.out.print("Enter amount:"); double amount=sc.nextDouble(); System.out.print("Enter commissionPercentage:"); double commissionPercentage=sc.nextDouble(); Calculate commission=new Calculate(amount , commissionPercentage); System.out.println("Commission amount="+commission.res); } } |
output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
Output:1 Enter amount:3000 Enter commissionPercentage:20 Commission amount=600.0 Output:2 Enter amount:10000000 Enter commissionPercentage:50 Commission amount=5000000.0 |
Learn More: