Product Calculation

// INCLUDING TAX WITH PRODUCT CALCULATION//

import java.util.Scanner;

public class TaxCalculator {

public static void main(String[] args) 

{

Scanner scanner = new Scanner(System.in);

        

// Define the tax rate (for example, 7% tax rate)

final double TAX_RATE = 0.07;

// Get the product name from the user

System.out.print("Enter the product name: ");

String productName = scanner.nextLine();

        

// Get the product amount from the user

System.out.print("Enter the product amount: ");

double amount = scanner.nextDouble();

        

// Calculate the tax

double tax = amount * TAX_RATE;

         

// Calculate the total amount including tax

double totalAmount = amount + tax;

        

// Display the result

System.out.printf("Product: %s%n", productName);

System.out.printf("Amount: $%.2f%n", amount);

System.out.printf("Tax (7%%): $%.2f%n", tax);

System.out.printf("Total Amount: $%.2f%n", totalAmount);

        

// Close the scanner

scanner.close();

    }

}


OUTPUT :


Enter the product name:Shirt

Enter the product amount: 150

Product: Shirt

Amount: $150.00

Tax (7%): $10.50

Total Amount: $160.50



//EXCLUDING TAX WITH PRODUCT CALCULATION//



import java.util.Scanner;

public class ExcludeTax {

public static void main(String[] args) 

{

Scanner scanner = new Scanner(System.in);

 // Get the product name from user

System.out.print("Enter the product name: ");

String productName = scanner.nextLine();

 // Get the amount (price including tax) from user

 System.out.print("Enter the amount (price including tax): ");

double amountWithTax = scanner.nextDouble();


// Define the tax rate (e.g., 15% tax rate)

double taxRate = 0.15;


// Calculate the amount excluding tax

double amountWithoutTax = amountWithTax / (1 + taxRate);


// Output the result

System.out.printf("The amount excluding tax for '%s' is: %.2f%n", productName, amountWithoutTax);


// Close the scanner

     scanner.close();

    }

}


OUTPUT:


Enter the product name: Watch

Enter the amount (price including tax): 250

The amount excluding tax for 'Watch' is: 217.39



Comments