//******************************Purchase items****************************** private void btnPurchaseActionPerformed(java.awt.event.ActionEvent evt) { //---Here is where we are going to calculate the tax and amt. due //---We will also format the money correctly so it look like a cash register. //---I use two data types to show you how to parse a string // Set the horizontal alignment for textboxes/labels to Right. //************************************************************************* NumberFormat currency = new DecimalFormat("#.00"); //no $ sign //NumberFormat myFormat = new DecimalFormat("$#.00"); //$ sign //************************************************************************ float price = Float.parseFloat(txtPrice.getText()); //---create a constant with the final keyword final float taxRate = .08F; double salesTax = price * taxRate; double balanceDue = price + salesTax; txtTax.setText(currency.format(salesTax)); txtBalanceDue.setText(currency.format(balanceDue)); txtPrice.setText(currency.format(price)); //make it look like $ also //---now display msg about sale lblMsg.setText("Thanks for shopping " + txtFirstName.getText() + " you spent " + txtBalanceDue.getText() + " today."); }