Product calculation
Product calculation
import java.util.Scanner;
public class ProductDetails {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Prompt for product name
System.out.print("P-Name: ");
String productName = scanner.nextLine();
// Prompt for quantity
System.out.print("Qty: ");
int quantity = scanner.nextInt();
// Prompt for price
System.out.print("Price: ");
double price = scanner.nextDouble();
// Prompt for tax percentage
System.out.print("Tax (%): ");
double tax = scanner.nextDouble();
// Calculate tax amount
double taxAmount = (tax / 100) * price;
// Calculate total amount (price + tax) per item
double totalPriceWithTax = price + taxAmount;
// Calculate total amount for all items
double totalAmount = totalPriceWithTax * quantity;
// Display the entered and calculated values
System.out.println("P. Name! " + productName);
System.out.println("Price: " + price);
System.out.println("Qty: " + quantity);
System.out.println("Tax: " + tax + "%");
System.out.println("Tax with Price (per item): " + totalPriceWithTax);
System.out.println("Total Amount: " + totalAmount);
System.out.println("Tax? " + taxAmount);
// Orignal
System.out.println("Original Price (without tax): " +
price);
scanner.close();
}
}
Comments
Post a Comment