UK Vat Calculator – Java Program

What it does:

A program which prompts the user to enter a number where it will then find out how much VAT will be added onto the item depending on its price. It will then give a new total with VAT added on. At the end of the program it will prompt the user to see if they would like to use the program again or if they would like to exit. This is done by a do-while loop. The program also features InputMismatchException to ensure that if the user enters a character by accident it will tell them what the issue was, allowing them to retry without the program crashing.


public class UKVatCalculator
    private static Scanner keyboard = new Scanner(;
    private static double number = 0;

    private static double amount()
       boolean complete =true;
       while (complete)
          System.out.println("Please enter the amount");

             number = keyboard.nextDouble();
             complete = false;

          catch(InputMismatchException IME)
             System.out.println("Whoops, you didn't enter a number.");



        //returning the value
        return number;

    private static void calculations()
        double taxTotal, total;

        taxTotal = number*0.20%100;

        total = number + taxTotal;

        System.out.println("The total tax to be added is £" + taxTotal);
        System.out.println(" ");
        System.out.println("The total with tax will be £" + total);
        System.out.println(" ");

    public static void main(String[] args)

        int runAgain;

        System.out.println("Welcome to the UK tax calculator!");

            //calling methods

            //Prompt to see if user would like to run again
            System.out.println("Would you like to run the program again?");
            System.out.println("Enter 1 for Yes");
            System.out.println("Enter 2 for No");
            runAgain = keyboard.nextInt();

        while (runAgain!=2);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s