GST calculation
INCLUDE GST CALCULATION
To calculate GST (Goods and Services Tax) in Java, you'll need to define a class to represent a product and then perform the calculations based on the quantity and GST rate.
Below is a simple Java program that demonstrates how to calculate the GST for a product.
JAVA CODE :
import java.util.Scanner;
public class GSTCalculator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter product name: ");
String productName = scanner.nextLine();
System.out.print("Enter quantity: ");
int quantity = scanner.nextInt();
System.out.print("Enter price per unit: ");
double pricePerUnit = scanner.nextDouble();
System.out.print("Enter GST rate (as percentage): ");
double gstRate = scanner.nextDouble();
double totalAmountBeforeGST = pricePerUnit * quantity;
double gstAmount = (gstRate / 100) * totalAmountBeforeGST;
double totalAmountIncludingGST = totalAmountBeforeGST + gstAmount;
System.out.printf("Product Name: %s%n", productName);
System.out.printf("Quantity: %d%n", quantity);
System.out.printf("Price per Unit: %.2f%n", pricePerUnit);
System.out.printf("GST Rate: %.2f%%%n", gstRate);
System.out.printf("Total Amount before GST: %.2f%n", totalAmountBeforeGST);
System.out.printf("GST Amount: %.2f%n", gstAmount);
System.out.printf("Total Amount including GST: %.2f%n", totalAmountIncludingGST);
scanner.close();
}
}
OUTPUT :
Enter product name: Keyboard
Enter quantity: 2
Enter price per unit: 1200
Enter GST rate (as percentage): 5
Product Name: Keyboard
Quantity: 2
Price per Unit: 1200.00
GST Rate: 5.00%
Total Amount before GST: 2400.00
GST Amount: 120.00
Total Amount including GST: 2520.00
=== Code Execution Successful ===
Comments
Post a Comment