Alright so this is just a neat little tutorial on how to code a basic tax rate calculator. It's nothing to difficult and it's pretty helpful if you're looking to buy items from your home. You can go to the cash register with the exact change! *These aren't part of my regular Java lessons but I just wanted to throw this one out to beginner coders. THIS IS VERY BASIC.

The first thing you want to do is an import statement, it's the first step in coding. Since we are accepting a String (non numeric data) we can load the JOptionPane class, which is allocated to swing which is allocated to javax so our import statement would look something like this:
Code:
 import javax.swing.JOptionPane;
//remember every statement or declaration ends with a semicolon (;)
Next let's define our class: *Reminder that since we are only defining a class we don't need to insert a semicolon.
Code:
import javax.swing.JOptionPane;

 
public class TaxRateCalculator
Since we will be using one method for this simple code we shall call it the main method.
You can name args anything you chose it's just the name of the allocated table of the function.


Code:
import javax.swing.JOptionPane

public class TaxRate Calculator
   {

    public static void main (String [] args)
        {
Next we want to declare our variables into temporary registers where we can asign certain type values of which we chose (int, double, char).
We need to keep in mind that we need. A cost. A tax. A total price with the tax. And a string location where the use can enter the cost. so 4 memory locations.

Not to confuse anyone but here in Quebec there's the TPS tax and the TVQ tax, so I assigned an extra memory location. You can chose the amount depending on where you live.

Here's what you would write
Code:
public class TaxRateCalculator
{
   public static void main (String [] args)
   {
      //variable declarations (Since we are dealing with 0.99 , 29.99 , 99.99 .. ect, we want a double type values for the entered cost.)
      //you can again name these temporary locations anything you chose. 

        
      double numCost;
      double numTps;
      double numTvq;
      double numtotalPrice;
      String inputString;
Here's where the little GUI (Graphical User Interface) happens with the JOptionPane class.
The string location we assigned shall be declared here. The showInputDialog class inserts a text box that use can enter the desired input.
The number that the user will enter was stated to be a double so we have the parse the string (non numeric data) into numeric data. so the conversion takes place in the numCost = Double.parseDouble (inputString) convering the inputString into an actually number we can work with.

Code:
inputString = 
      JOptionPane.showInputDialog ("Enter price of item:");
      numCost = Double.parseDouble (inputString);
This is the easy processing step.
Whatever the user entered as cost will multiplied by the taxes and stored in its own location.


Code:
//determine tax price
numTps = numCost * 0.05;
      numTvq = numCost * 0.095;
You can guess what we're going to do next right? All you have to do is add the tax price to the desired cost, put it in the memory location, which we stated was a double value and you're all set.. almost all set.

Code:
numtotalPrice = numCost + numTps + numTvq;
Last thing we have to do is create an output so the user can look at the desired result and end our class.
System.out.println is the command which will create another box which will tell us the output. you must enter the dialog ("Cost of item is " +numtotalPrice);
make sure you leave a space after your dialog so it doesn't look all crammed up. what the +numtotalPrice does is add the contents of the memory location into the dialog.

Code:
System.out.println ("Cost of item is   " + numtotalPrice);
       }
}

So in total we can add everything up and get:

Code:
public class TaxRateCalculator
{
   public static void main (String [] args)
   {
      //variable declarations

      double numCost;
      double numTps;
      double numTvq;
      double numtotalPrice;
      String inputString;
      
      //accept the inputed date and converte it to approriate data type
      
      inputString = 
      JOptionPane.showInputDialog ("Enter price of item:");
      numCost = Double.parseDouble (inputString);
      
      //Determine the tax price
      
      numTps = numCost * 0.05;
      numTvq = numCost * 0.095;
      
      //Determine tax price + Cost
      
      numtotalPrice = numCost + numTps + numTvq;
      
      System.out.println ("Cost of item is   " + numtotalPrice);
      
      }
}
Don't forget to save it as a .class file once it's compiled it into machine language it will be a .java file and there you have it. A tax rate calculator. Hope I was of help to you. - Jeff