import java.util.InputMismatchException;

import java.util.Scanner;


public class ProductCalculation {


    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        

        try {

            // Input product details

            System.out.print("P. Name: ");

            String productName = scanner.nextLine();

            

            System.out.print("Quantity: ");

            int quantity = scanner.nextInt();

            

            System.out.print("Price: ");

            double price = scanner.nextDouble();

            

            System.out.print("Tax: ");

            double tax = scanner.nextDouble();

            

            // Calculate total amount

            double totalAmount = (price * quantity) * (1 + tax / 100);

            

            // Print the first set of details

            System.out.println("\nProduct Calculation");

            System.out.println("P. Name: " + productName);

            System.out.println("Quantity: " + quantity);

            System.out.println("Price: " + price);

            System.out.println("Tax: " + tax + "%");

            System.out.println("Total amount: " + totalAmount);

            

            // Print the second set of details

            System.out.println("\nInclude tax:");

            System.out.println("P. Name: " + productName);

            System.out.println("Quantity: " + quantity);

            System.out.println("Tax with price: " + (price * (1 + tax / 100)));

            System.out.println("Tax: " + tax + "%");

            System.out.println("Original Price: " + price);

            

        } catch (InputMismatchException e) {

            System.out.println("Invalid input. Please enter the correct data type.");

        } finally {

            scanner.close();

        }

    }

}


Comments