In: Computer Science
A retail company must file a monthly sales tax report listing the total sales for the month, and the amount of state and county sales tax collected. The state sales tax rate is 5 percent and the county sales tax rate is 3 percent. Create a GUI application that allows the user to enter the total sales for the month into a text field. From this figure, the application should calculate and display the following: The number of county sales tax The amount of state sales tax The total sales tax (county plus state)
CODE: SalesTax.java
import javax.swing.*;
import java.awt.event.*;
class MonthlySalesTax extends JFrame{
private JPanel panel;
private JLabel messageLabel_monthlysales;
private JTextField monthlysalesTextField;
private JButton saletaxButton;
private final int WINDOW_WIDTH = 250;
private final int WINDOW_HEIGHT = 250;
public MonthlySalesTax(){
setTitle("Monthly Sales
Tax");
setSize(WINDOW_WIDTH,
WINDOW_HEIGHT);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
buildPanel();
add(panel);
setVisible(true);
}
private void buildPanel(){
messageLabel_monthlysales = new
JLabel("Enter Total sales for the month ");
monthlysalesTextField = new
JTextField(10);
saletaxButton = new
JButton("Calculate Monthly Sales Tax");
saletaxButton.addActionListener(new
CalculateMST());
panel = new
JPanel();
panel.add(messageLabel_monthlysales);
panel.add(monthlysalesTextField);
panel.add(saletaxButton);
}
public class CalculateMST implements
ActionListener{
public void
actionPerformed(ActionEvent e){
String
input;
double
CountyTax;
double
StateTax;
double
TotalsalesTax;
input =
monthlysalesTextField.getText();
CountyTax =
(Double.parseDouble(input)* 0.03);
StateTax =
(Double.parseDouble(input)* 0.05);
TotalsalesTax =
(CountyTax + StateTax);
JOptionPane.showMessageDialog(null, " The Amount Of County Sales
Tax : " + CountyTax + "\n The Amount Of State Sales Tax : "
+ StateTax + "\n The Total Sales Tax
: " + TotalsalesTax );
}
}
}
public class SalesTax{
public static void main(String[] args){
MonthlySalesTax ST = new
MonthlySalesTax();
}
}
SCREENSHOT OF THE CODE:
OUTPUT:
The total sales for the month i have taken 20000.
5% on The State sales tax is 1000.0 = (5/100)*20000.
3% in County sales tax is 600.0 = (3/100) *20000