product calcalation

                    JAVA PROGRAMMING
         
            Including Tax and Excluding Tax

import java.text.DecimalFormat;

class ProductExcludingTax {
    private String productName;
    private int quantity;
    private double price;
    private double taxRate; 

    
    public ProductExcludingTax(String productName, int quantity, double price, double taxRate) {
        this.productName = productName;
        this.quantity = quantity;
        this.price = price;
        this.taxRate = taxRate;
    }

    
    public double calculateTotalAmount() {
        double totalAmount = quantity * price;
        double taxAmount = totalAmount * taxRate;
        return totalAmount + taxAmount;
    }

    
    public void display() {
        DecimalFormat df = new DecimalFormat("#.##");
        double totalAmount = calculateTotalAmount();
        
        System.out.println("Product name: " + productName);
        System.out.println("Quantity: " + quantity);
        System.out.println("Price per unit: $" + df.format(price));
        System.out.println("Tax rate: " + (taxRate * 100) + "%");
        System.out.println("Total amount (including tax): $" + df.format(totalAmount));
    }
}


class ProductIncludingTax {
    private String productName;
    private int quantity;
    private double originalPrice; 
    private double taxAmount; 
    private double taxRate;

    
    public ProductIncludingTax(String productName, int quantity, double originalPrice, double taxRate) {
        this.productName = productName;
        this.quantity = quantity;
        this.originalPrice = originalPrice;
        this.taxRate = taxRate;
        this.taxAmount = originalPrice * taxRate;
    }

    
    public void display() {
        DecimalFormat df = new DecimalFormat("#.##");
        
        System.out.println("Product name: " + productName);
        System.out.println("Quantity: " + quantity);
        System.out.println("Tax included price per unit: $" + df.format(originalPrice));
        System.out.println("Tax rate: " + (taxRate * 100) + "%");
        System.out.println("Tax amount: $" + df.format(taxAmount));
        System.out.println("Original price (excluding tax): $" + df.format(originalPrice - taxAmount));
    }
}

public class Main {
    public static void main(String[] args) {
        
        ProductExcludingTax product1 = new ProductExcludingTax("Book", 3, 15, 5);
        product1.display();
        System.out.println(); 
        
        
        ProductIncludingTax product2 = new ProductIncludingTax("Laptop", 1, 150.0, 0.10);
        product2.display();
    }
}


Output:-

Product name: Book
Quantity: 3
Price per unit: $15
Tax rate: 500.0%
Total amount (including tax): $270
Product name: Laptop
Quantity: 1
Tax included price per unit: $150
Tax rate: 10.0%
Tax amount: $15
Original price (excluding tax): $135

Popular posts from this blog

PROFILE CREATING

First program

RESUME