Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLEASE NOTE I WANT THIS CODE IN JAVA USING GUI APPLICATION ONLY. (USING JPANE, J

ID: 3827342 • Letter: P

Question

PLEASE NOTE I WANT THIS CODE IN JAVA USING GUI APPLICATION ONLY. (USING JPANE, JLABEL, JTEXTFIELD, JBORDER........)

Monthly Sales Tax

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 4 percent and the county sales tax rate is 2 percent. Create a GUI application that allows the user to calculate and display the following:

The amount of county sales tax

The amount of state sales tax

The total sales tax (county plus state)

In the application’s code, represent the county tax rate (0.02) and the state tax rate (0.04) as named constants.

Explanation / Answer

Here’s the java code for the above question,

import java.awt.BorderLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.text.DecimalFormat;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JTextField;

//Create a Class

public class MonthlySalesTax extends JFrame

{

private static final long serialVersionUID = 1L;

private static final double COUNTY_TAX = 0.02;

private static final double STATE_TAX = 0.04;

private static final int WINDOW_WIDTH = 320;

private static final int WINDOW_HEIGHT = 105;

private static JPanel panel;

private static JTextField totalSalesTextField;

private static JButton calcButton;

private static JLabel messageLabel;

public MonthlySalesTax()   // Constructor

{

JFrame window = new JFrame(); // create a window

window.setTitle("Monthly Sales Tax Calculator"); // Display a title

window.setSize(WINDOW_WIDTH, WINDOW_HEIGHT); // set the size of the window

window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Specify an action for the                       close button

window.setLayout(new BorderLayout()); // Create a BorderLayout manager

buildPanel(); // Build the panel and add it to the frame

window.add(panel); // Add the panel to the frame's content pane

window.setVisible(true); // Display the window

}

private void buildPanel()

{

// Create a label to display instructions

messageLabel = new JLabel("Please enter the total sales " + "for the month");

// Create a text field 10 characters wide.

totalSalesTextField = new JTextField(10);

// Create a button with the caption "Calculate".

calcButton = new JButton("Calculate");

// Add an action listener to the button.

calcButton.addActionListener(new CalcButtonListener());

// Create a JPanel object and let the panel

// field reference it.

panel = new JPanel();

// Add the label, text field, and button

// components to the panel.

panel.add(messageLabel);

panel.add(totalSalesTextField);

panel.add(calcButton);

}

/**

* CalcButtonListener is an action listener class for

* the Calculate button.

*/

private class CalcButtonListener implements ActionListener

{

/**

* The actionPerformed method executes when the user

* clicks on the Calculate button.

* @parameter e The event object.

*/

public void actionPerformed(ActionEvent e)

{

String input; // to hold the users input

double totalSales; // convert the string input to totalSales

double countyTax;

double stateTax;

double stateCountyTotal;

String message;

DecimalFormat df = new DecimalFormat("#0.00");

// Get the text entered by the user into the text field.

input = totalSalesTextField.getText();

// Convert input to double totalSales.

totalSales = Double.parseDouble(input);

// calculations part

countyTax = totalSales * COUNTY_TAX;

stateTax = totalSales * STATE_TAX;

stateCountyTotal = stateTax + countyTax;

// Display the result.

message = "The amount of county sales tax is $"

+ df.format(countyTax) + " The amount of state sales tax is $"

+ df.format(stateTax) + " The total sales tax is $"

+ df.format(stateCountyTotal);

JOptionPane.showMessageDialog(null, message);

}

}

// Main function

public static void main(String[] args)

{

MonthlySalesTax taxObject = new MonthlySalesTax();

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote