Program 1



PROGRAM-01

public class BookPriceCalculator {

    public static void main(String[] args) {
        String productName = "Book";
        int quantity = 5;
        double taxRate = 0.1; // Assuming tax rate is 10%

        double originalPrice = 20.0; // Assuming original price of each book is $20

        // Calculate tax amount
        double taxAmount = originalPrice * taxRate;

        // Calculate total price including tax
        double totalPrice = (originalPrice + taxAmount) * quantity;

        // Print out the details
        System.out.println("Product name: " + productName);
        System.out.println("Quantity: " + quantity);
        System.out.println("Original Price per book: $" + originalPrice);
        System.out.println("Tax Rate: " + (taxRate * 100) + "%");
        System.out.println("Tax Amount per book: $" + taxAmount);
        System.out.println("Total Price including tax: $" + totalPrice);
    }
}


PROGRAM-2

import java.util.Scanner;

class Product {
    String name;
    int quantity;
    double price;
    double tax;

    // Constructor
    public Product(String name, int quantity, double price, double tax) {
        this.name = name;
        this.quantity = quantity;
        this.price = price;
        this.tax = tax;
    }

    // Method to calculate the total amount
    public double calculateTotalAmount() {
        double totalPrice = price * quantity;
        double totalTax = totalPrice * (tax / 100);
        return totalPrice + totalTax;
    }
}

public class ProductCalculation {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // Taking input from the user
        System.out.println("Enter product name:");
        String name = scanner.nextLine();

        System.out.println("Enter quantity:");
        int quantity = scanner.nextInt();

        System.out.println("Enter price per unit:");
        double price = scanner.nextDouble();

        System.out.println("Enter tax percentage:");
        double tax = scanner.nextDouble();

        // Creating Product object
        Product product = new Product(name, quantity, price, tax);

        // Calculating total amount
        double totalAmount = product.calculateTotalAmount();

        // Displaying the product details and total amount
        System.out.println("\nProduct Details:");
        System.out.println("Name: " + product.name);
        System.out.println("Quantity: " + product.quantity);
        System.out.println("Price per unit: " + product.price);
        System.out.println("Tax: " + product.tax + "%");
        System.out.println("Total Amount: $" + totalAmount);
    }
}













Comments

Popular posts from this blog

Java Quiz program