GST Calculation Program in Core Java


This example demonstrates a  GST calculation in Core Java. You can modify the `price` and `gstRate` variables to suit your needs or enhance the program to take user input for these values.
I can help you develop a  GST (Goods and Services Tax) calculation program in Core Java.

Below is an example program that calculates the GST for a given product price and GST rate.

GST Calculation Program in Core Java


public class GSTCalculator {
    // Method to calculate GST
    public static double calculateGST(double price, double gstRate) {
        double gstAmount = (price * gstRate) / 100;
        return gstAmount;
    }

    // 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;
       return gstAmount;
   }
   
   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.

3. Main Method:
   
   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:

Original Price: 1000.0
GST Rate: 18.0%
GST Amount: 180.0
Total Price after GST: 1180.0



No comments:

INTRODUCTION TO COMPUTER NETWORKS

A Computer network consists of two or more autonomous computers that are linked (connected) together in order to: • Share resources (files...