Skip to main content

Java Program

                             Product Calculation 

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", 2, 25.0, 0.08);
        product1.display();
        System.out.println();
        ProductIncludingTax product2 = new ProductIncludingTax("Laptop", 1, 1500.0, 0.10); 
        product2.display();
    }
}

Output:

Product name: Book
Quantity: 2
Price per unit: $25.0
Tax rate: 8.0%
Total amount (including tax): $54.0

Product name: Laptop
Quantity: 1
Tax included price per unit: $1500.0
Tax rate: 10.0%
Tax amount: $150.0
Original price (excluding tax): $1350.0

Comments

Popular posts from this blog

Qvesys AI Summer Course 2026

Qvesys AI Summer Course 2026 | Kumbakonam | School & College Students QVESYS 📞 Register Now Summer 2026 · Kumbakonam · Limited Seats BUILD YOUR FUTURE Qvesys Info-Tech presents an intensive summer tech training crafted for school & college students in Kumbakonam. Learn AI, Coding & more — from scratch to skill. 📞 Call & Register — 8220015195 🌐 Visit qvesys.in 5 Expert Co...

Qvesys Summer Course 2026

Qvesys Summer Course 2026 | Kumbakonam | AI · Cybersecurity · Python · Data Science QVESYS 📞 Register Now Summer 2026 · Kumbakonam · Limited Seats SECURE YOUR FUTURE Qvesys Info-Tech presents a summer tech training for school & college students in Kumbakonam. From Cybersecurity to AI — build real skills that employers want. 📞 Call Now — 8220015195 🌐 qvesys.in ...

Email Marketing Automation & Lead Magnet Creation: Step-by-Step Side Project Template for Beginners

 Email Marketing Automation & Lead Magnet Creation: Step-by-Step Side Project Template for Beginners Introduction Email Marketing Automation and Lead Magnet Creation is one of the most powerful strategies to generate consistent leads and build a scalable online business. If you're looking to start a side project that generates income while helping businesses grow, this model is highly effective. In simple terms, you create valuable content (called lead magnets ) like ebooks, checklists, or reports. Businesses offer these for free in exchange for email addresses—helping them build their customer base. You can monetize this by offering lead magnet creation services, automation setup, and consulting . This guide will walk you step-by-step through creating your own Email Marketing Automation & Lead Magnet Creation side project . What is Email Marketing Automation & Lead Magnet Creation? Email Marketing Automation Email marketing automation is the process of sending e...