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

Profile

Gokila Kiruba View Full Size Contact me Email On Blogger since June 2024 Profile views - 3 Report Abuse My blogs Gokila Kiruba About me Gender Female Industry Student Location Kumbakonam,   TamilNadu,   India Introduction Hi, I’m Gokila Kiruba. I’m currently pursuing my MSc in Computer Science, having completed my BSc in the same field. I have experience in software development, especially with technologies like HTML, Bootstrap, JavaScript, and Java. I’m currently working on projects that involve dynamic web applications and basic database operations. I enjoy learning new things and solving technical challenges. Interests I’m on an exciting journey in the world of computer science. With a passion for technology, I’ve been crafting web applications using tools like HTML, Bootstrap, JavaScript, and Java. I’m always up for a challenge, whether it’s making a website more interactive or diving into database management. I love exploring new ideas and pushing the boundaries of what I...

Student Blog's

STUDENT BLOGS  S.NO NAME REGISTER NO BLOG LINK 1. AKASH .N P23CS366 1.  Product Calculation 2.  Question and Answer 3.  File Operation 4.  Profile 2. AMMU .M P23CS367 1.  Product Calculation 2.  Question and Answer 3.  File Operation 4.  Profile 3. ANBU .M P23CS368 1.  Product Calculation 2.  Question and Answer 3.  File Operation 4.  Profile 4. ANBUMANI .A P23CS369 1.  Product Calculation 2.  Question and Answer 3.  File Operation 4.  Profile 5. ARAVINDHAN .A P23CS370 1.  Product Calculation 2.  Question and Answer 3.  File Operation 4.  Profile 6. BARATH .M P23CS371 1...
 File Operation EXPLANATION : -    File operations involve interacting with files on a computer system, allowing you to create, read, write, and delete files. Common operations include: 1. Open a file – Access a file to read or modify it. 2. Read from a file– Extract data from the file. 3. Write to a file– Add or modify data in the file. 4. Close a file– End the interaction with the file to free up system resources. 5. Delete a file – Remove the file from the system.  These actions help manage data in programs and applicationsapplications PROGRAM:- import java.io.File; import java.io.*; import java.io.FileWriter; import java.io.FileReader; import java.io.BufferedReader; import java.io.IOException; class FSC{      public static void main(String args[])throws IOException { int i; DataInputStream d = new DataInputStream(System.in); String fileName = "msc1.txt"; do { System.out.println("\nwhich type of file operation you want to perform?"); System.out.prin...