public class GSTCalculator {
// Method to calculate GST
public static double calculateGST(double price, double gstRate) {
double gstAmount = (price * gstRate) / 100;
// Method to calculate total price after GST
public static double calculateTotalPrice(double price, double gstRate) {
double gstAmount = calculateGST(price, gstRate);
return price + gstAmount;
public static void main(String[] args) {
double price = 1000.0; // Example price
double gstRate = 18.0; // Example GST rate
double gstAmount = calculateGST(price, gstRate);
double totalPrice = calculateTotalPrice(price, gstRate);
System.out.println("Original Price: " + price);
System.out.println("GST Rate: " + gstRate + "%");
System.out.println("GST Amount: " + gstAmount);
System.out.println("Total Price after GST: " + totalPrice);
Explanation
1. GST Calculation Method:
public static double calculateGST(double price, double gstRate) {
double gstAmount = (price * gstRate) / 100;
This method calculates the GST amount based on the price and GST rate.
2. Total Price Calculation Method:
public static double calculateTotalPrice(double price, double gstRate) {
double gstAmount = calculateGST(price, gstRate);
return price + gstAmount;
This method calculates the total price after adding the GST amount to the original price.
public static void main(String[] args) {
double price = 1000.0; // Example price
double gstRate = 18.0; // Example GST rate
double gstAmount = calculateGST(price, gstRate);
double totalPrice = calculateTotalPrice(price, gstRate);
System.out.println("Original Price: " + price);
System.out.println("GST Rate: " + gstRate + "%");
System.out.println("GST Amount: " + gstAmount);
System.out.println("Total Price after GST: " + totalPrice);
This method sets the example price and GST rate, calculates the GST amount and total price, and prints the results.
Output
Running the above program will produce the following output:
Total Price after GST: 1180.0
No comments:
Post a Comment