JAVA PROGRAMMING (tax)
DESCRIPTION :
★ This program about the exclude and include tax of the products.
★ ProductExcludingTax class used to calculate the excludetax of product.
★ ProductExcludingTax()-for gathering the products details.
★ CalculateTotalAmount()-for calculate the excluding Tax.
★ Void display () - for display the calculated excluding tax.
★ Product including Tax class used to calculate the including tax of product.
it has three functions,
★ ProductincludingTax()-for gathering the products details.
★ CalculateTotalAmount()-for calculate the including Tax.
★ Void display () - for display the calculated including tax.
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 * 10) + "%");
System.out.println("Total amount (including tax): " + df.format(totalAmount));
}
}
public class Main
{
public static void main(String[] args)
{
ProductExcludingTax product1 = new ProductExcludingTax("Pencil", 2, 5, 8);
product1.display();
System.out.println();
}
}
OUTPUT :
Product name: Pencil
Quantity: 2
Price per unit: 5
Tax rate: 80.0%
Total amount (including tax): 90
INCLUDING TAX
import java.text.DecimalFormat;
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 * 10) + "%");
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)
{
ProductIncludingTax product2 = new ProductIncludingTax("Book", 1, 150, 8);
product2.display();
}
}
OUTPUT :
Product name: Book
Quantity: 1
Comments
Post a Comment