Java Program to Find Total Amount After Adding Tax

In the previous article, we have seen Java Program to Convert Meter to Yard and Yard to Meter

In this article we will see how to calculate percentage of tax in total amount using Java programming language.

Java Program to Find Total Amount After Adding Tax

We have to find total amount after adding tax amount.

Let’s take an scenario of tax imposed on price.

  • If total amount of product is below 1000 then No tax on total amount.
  • If total amount of product crosses 1000 but below 5000 then 5% tax on total amount.
  • If total amount of product crosses 5000 but below 10000 then 8% tax on total amount.
  • If total amount of product crosses 10000  then 10% tax on total amount.

Let’s see different ways to find total amount after adding tax,

Method-1: Java Program to Find Total Amount After Adding Tax By Using Static Input Value

Approach:

  • Declare initial amount value.
  • Check as per above mentioned tax condition and find tax based on initial amount.
  • Then after adding the tax with the amount, we can get total amount.
  • Print total amount.

Program:

public class Main
{
    public static void main(String[] args) 
    {
        //amount declared
        double amount = 2000;
        //double variable 'tax' initualized to 0
        double tax=0;
        //double variabe 'totalAmount' initialized to 0
        double totalAmount = 0;
        
        //if amount below than 1000 then no tax
        if(amount < 1000)
        {
            totalAmount=amount;
        }
        //if amount is in between 1000 and 5000
        //then 5% tax
        else if ((amount > 1000) && (amount < 5000)) 
        {
            tax=(amount*5)/100;
            totalAmount=amount+tax;
        }
        //if amount is in between 5000 and 10000
        //then 8% tax
        else if ((amount > 5000) && (amount < 10000)) 
        {
            tax=(amount*8)/100;
            totalAmount=amount+tax;

        }
        //else amount is more than 10000
        //then 10% tax
        else if (amount > 10000)
        {
            tax=(amount*10)/100;
            totalAmount=amount+tax;
        }
        //printing total amount after adding tax
        System.out.println("Total Amount " + totalAmount);
    }
}
Output:

Total Amount 2100.0

Method-2: Java Program to Find Total Amount After Adding Tax By Using User Input Value

Approach:

  • Take user input of initial amount value.
  • Check as per above mentioned tax condition and find tax based on initial amount.
  • Then after adding the tax with the amount, we can get total amount.
  • Print total amount.

Program:

import java.util.*;

public class Main
{
    public static void main(String[] args) 
    {
        //Scanner class object created
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter amount: " );
        //taking amount value input from user
        double amount = sc.nextInt();
        //double variable 'tax' initualized to 0
        double tax=0;
        //double variabe 'totalAmount' initialized to 0
        double totalAmount = 0;
        
        //if amount below than 1000 then no tax
        if(amount < 1000)
        {
            totalAmount=amount;
        }
        //if amount is in between 1000 and 5000
        //then 5% tax
        else if ((amount > 1000) && (amount < 5000)) 
        {
            tax=(amount*5)/100;
            totalAmount=amount+tax;
        }
        //if amount is in between 5000 and 10000
        //then 8% tax
        else if ((amount > 5000) && (amount < 10000)) 
        {
            tax=(amount*8)/100;
            totalAmount=amount+tax;

        }
        //else amount is more than 10000
        //then 10% tax
        else if (amount > 10000)
        {
            tax=(amount*10)/100;
            totalAmount=amount+tax;
        }
        //printing total amount after adding tax
        System.out.println("Total Amount after adding tax: " + totalAmount);
    }
}
Output:

Enter amount: 
6000
Total Amount after adding tax: 6480.0

Method-3: Java Program to Find Total Amount After Adding Tax By Using User Defined Method

Approach:

  • Take user input of initial amount value.
  • Then call a method by passing this amount as parameter.
  • Inside method check as per above mentioned tax condition and find tax based on initial amount.
  • Then after adding the tax with the amount, we can get total amount.
  • Print total amount.

Program:

import java.util.*;

public class Main
{
    public static void main(String[] args) 
    {
        //Scanner class object created
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter amount: " );
        //taking amount value input from user
        double amount = sc.nextInt();
        //calling a user defined method findAmount()
        findAmount(amount);
    }
    
    //findAmount() method to find total amount after adding tax
    public static void findAmount(double amount)
    {
        //double variable 'tax' initualized to 0
        double tax=0;
        //double variabe 'totalAmount' initialized to 0
        double totalAmount = 0;
        
        //if amount below than 1000 then no tax
        if(amount < 1000)
        {
            totalAmount=amount;
        }
        //if amount is in between 1000 and 5000
        //then 5% tax
        else if ((amount > 1000) && (amount < 5000)) 
        {
            tax=(amount*5)/100;
            totalAmount=amount+tax;
        }
        //if amount is in between 5000 and 10000
        //then 8% tax
        else if ((amount > 5000) && (amount < 10000)) 
        {
            tax=(amount*8)/100;
            totalAmount=amount+tax;

        }
        //else amount is more than 10000
        //then 10% tax
        else if (amount > 10000)
        {
            tax=(amount*10)/100;
            totalAmount=amount+tax;
        }
        //printing total amount after adding tax
        System.out.println("Total Amount after adding tax: " + totalAmount);
    }
}
Output:

Enter amount: 
12000
Total Amount after adding tax: 13200.0

Our website provided core java programs examples with output aid beginners and expert coders to test their knowledge gap and learn accordingly.

Related Java Programs: