Java Program to Calculate Commission Percentage

In the previous article we have discussed about Java Program to Calculate Batting Average

In this program we are going to see how to calculate commission percentage by using Java programming language.

Java Program to Calculate Commission Percentage

Before jumping into the program directly, let’s know how to calculate commission percentage.

Commission percentage= (commission / amount) * 100

Example:

Suppose amount = 1000
commission= 200
Then, Commission percentage= (commission/amount)*100
= (200/1000)*100
= 20

Now let’s see different ways to compute commission percentage.

Method-1: Java Program to Calculate Commission Percentage By Using Static Input Value

Approach:

  • Declare and initialize two double variables say commission and amount.
  • By using the formula compute commission percentage and store it in an integer variable commission_percentage.
  • Print the result.

Program:

class Main
{
    public static void main(String arg[])
    {
        // Declare and initialize two double variables say commission and amount
        double commission=200,amount=1000;
        //Declare an another double  variable to store the computed value
        double commission_percentage;
        commission_percentage =(commission/amount)*100;
        //Print the result
        System.out.println("The commission percentage= "+ commission_percentage+ "%");
    }
}
Output:

The commission percentage= 20.0%

Method-2: Java Program to Calculate Commission Percentage By using user input value

Approach:

  • Declare and initialize two double variables say commission and amount.
  • Prompt the user to enter the values to the corresponding variables.
  • By using the formula compute commission percentage and store it in an integer variable commission_percentage.
  • Print the result.

Program:

import java.util.Scanner;
class Main
{
    public static void main(String arg[])
    {
        // Declare and initialize two double variables say commission and amount
        double commission,amount;
        //create the scanner class object
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter the amount= ");
      	amount=sc.nextInt();
        System.out.print("Enter the commission amount= ");
        commission=sc.nextInt();
        double commission_percentage;
        commission_percentage =(commission/amount)*100;
        //Print the result
        System.out.println("The commission percentage= "+ commission_percentage+ "%");
    }
}
Output:

Enter the amount= 2000
Enter the commission amount= 240
The commission percentage= 12.0%

Method-3: Java Program to Calculate Commission Percentage By Using User Defined Method

Approach:

  • Declare and initialize two double variables say commission and amount.
  • Prompt the user to enter the values to the corresponding variables.
  • Then call a user defined method say computeValue() by passing commission and amount as parameter.
  • Then inside method by using the formula compute commission percentage and store it in an integer variable commission_percentage.
  • Print the result.

Program:

import java.util.Scanner;
class Main
{
    public static void main(String[] args)
    {
        // Declare and initialize two double variables say commission and amount
        double commission,amount;
        //create the scanner class object
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter the amount= ");
      	amount=sc.nextInt();
        System.out.print("Enter the commission amount= ");
        commission=sc.nextInt();
        //call the user defined method
        computeValue(amount,commission);
    }
    //define the method
    public static void computeValue(double a, double b)
    {
        //declare another double variable and assigned the formulated value to it.
        double commission_percentage;
        commission_percentage =(b/a)*100;
        //Print the result
        System.out.println("The commission percentage= "+ commission_percentage+ "%");
    }
}
Output:

Enter the amount= 5000
Enter the commission amount= 500
The commission percentage= 10.0%

Enhancing programming skills is very important no matter what language you have chosen. So, practice frequently with these simple java programs examples and excel in coding the complex logic.

Try yourself:

  1. write a program to calculate commission for the salesman
  2. write a program to calculate commission for the salesman
  3. Program to calculate power of number in java
  4. Program to calculate salesperson commission in c
  5. Calculate depreciation of value in java
  6. Count sales designation program in java
  7. Calculating sales java program
  8. Program to calculate salesperson commission in python
  9. 1000 java programs

Related Java Programs: