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

//Folder/Project Name: Ch3PayrollApplication //Programmer Name: example //Date:

ID: 3640979 • Letter: #

Question

//Folder/Project Name: Ch3PayrollApplication
//Programmer Name: example
//Date: 03/24/2012
//Class Name: PayrollApplication
/*Project Description: This payroll project uses a GUI to input rate and hours
* and then outputs the gross pay using swing components
*/
import javax.swing.*; //for swing components
import java.awt.*; // for Font
import java.awt.event.*; //for actionListener

public class PayrollApplication extends JFrame
implements ActionListener
{
//declare your instance objects here
JPanel mainPanel = new JPanel();
JLabel companyLabel = new JLabel(" A B C C o m p a n y ");
JLabel nameLabel = new JLabel("Employee name: ");
JLabel hoursLabel = new JLabel ("Hours worked: ");
JLabel hourlyRateLabel = new JLabel("Hourly rate: ");
JTextField nameTextField = new JTextField(20);
JTextField hoursTextField = new JTextField(20);
JTextField hourlyRateTextField = new JTextField(20);
JButton calculateButton = new JButton("Calculate Gross Pay");
JTextArea outputTextArea = new JTextArea(5, 20);
JScrollPane outputScrollPane = new JScrollPane(outputTextArea); //For scrollbars around text area

Font bigFont = new Font("Times New Roman", Font.BOLD, 28);

// This is the first method called in a application
//We will create an object of ourselves to call the
//constructor and then set the default close operation for the frame
public static void main(String[] args)
{

PayrollApplication basicGUI = new PayrollApplication();
basicGUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}//end of main

//This is the constructor for this class. It will be called from main
//It will set up our GUI panel with needed components
//and set up appropriate event listening
public PayrollApplication()
{
//call the superclass' constructor and send a title
super("Gross Pay Application");

//add GUI components to the appropriate container
mainPanel.add(companyLabel);
companyLabel.setFont(bigFont);
companyLabel.setForeground(Color.RED);
mainPanel.add(nameLabel);
mainPanel.add(nameTextField);
mainPanel.add(hoursLabel);
mainPanel.add(hoursTextField);
mainPanel.add(hourlyRateLabel);
mainPanel.add(hourlyRateTextField);
mainPanel.add(calculateButton);
mainPanel.add(outputScrollPane);

//add the JPanel to the JFrame
add(mainPanel);

//call the listeners method
addListeners();

//set the properties of the JFrame for display
this.setSize(300, 500);
this.setVisible(true);
}//end of constructor

//Used to register the components to the action listener
public void addListeners()
{
calculateButton.addActionListener(this);
hourlyRateTextField.addActionListener(this);
}

//Retrieve and convert textfields and calculate and display the gross pay
public void actionPerformed(ActionEvent evt)
{

}

}//end of class

*note: This is an example of the format I have to follow. Below is the project have to follow. Can anyone please help me with this project? This is very urgent. Please and thank you. For the company name, I will make that up.*


Project Description
Write a JFrame GUI application that calculates the shipping charge for a package, based on its weight. The user will input a six digit identification code, weight in pounds and ounces each in separate text fields. After the user clicks a calculation button, the program must display the package ID, the weight in pounds and ounces and the shipping charge in a text area. The shipping rate is $0.12 per ounce. Accumulate the total shipping charges for all of the packages and the number of packages processed and display each of these items in individual labels. Include the fictitious name of your company as a label at the top of your frame, displaying the company name in a larger font than the rest of the fields in the interface. Include a label at the bottom of the interface containing your name as the developer.
Interface Layout and Input
Include the fictitious name of your company as a label at the top of your frame, displaying the company name in a larger font than the rest of the fields in the interface.
Include the following labeled text fields for user input:
• Package-identification code (a six-digit code)
• Weight of the package—one text field for pounds and another text field for ounces
Include a button to trigger the calculations and display the results.
Include a text area for displaying the results of the current order.
Include individual labels for both the total accumulated shipping charges for all orders and the total number of packages processed for all orders.
Include a label at the bottom of the interface containing your name as the developer.
Processing
After the user has input the package ID code, the pounds and the ounces, convert the weight to ounces and calculate the cost based on a shipping rate of $.12 per ounce.
Accumulate the total shipping charges for all packages entered and the number of packages processed.
Calculation hint: There are 16 ounces in a pound.
You must use constants for the shipping rate (.12) and the conversion rate of 16 ounces/pound.

Output
Display the package ID, the weight in pounds and ounces formatted as shown in the Weight column under Sample Data below and the shipping charge in the text area.
Display the total shipping charges for all packages and the number of packages processed in individual labels (or text fields that are not editable).
Format the Weight as ___ lb. ___ oz.
Format your shipping charge to include a dollar sign and 2 decimal places.
Other Requirements
You must ensure that you do not code your entire application in the main method. Use a constructor to build the user interface and the actionPerformed method of the ActionListener interface to respond to the user’s entry and do the calculations needed. You may break the task into more methods than described above, if you prefer.
Also, try to use the setSize method of the JFrame to position your fields so that the interface is readable (labels next to the matching text fields, etc. Remember that you can also help to determine the size of your components when you declare them. Extra spaces in a label or button could help to line up items for a better interface look.
Sample Data Calculation
Test Data (Input) Check Figures (Answer)
ID Weight Shipping Charge
Z0000Z 1 lb. 1 oz. $2.04

Use correct naming conventions in your program. Indent the program source code correctly, leaving blank lines where appropriate. Include the recommended remarks in the Java source code (including complete comments at the top of the class and comments before each method.
I consider documentation a vital part of every project, and will deduct points increasingly every time that you do not include the appropriate comments or other items of documentation as part of your project.

Explanation / Answer

Please rate...

import javax.swing.*;
import java.awt.*; // for Font
import java.awt.event.*; //for actionListener

public class ShippingRate extends JFrame implements ActionListener
{
    JPanel mainPanel = new JPanel();
    JLabel companyLabel = new JLabel(" A B C C o m p a n y ");
    JLabel idLabel = new JLabel("*********************ID Code: ");
    JLabel spaceLabel = new JLabel("************");
    JLabel weightLabel = new JLabel("**************Weight: ***************");
    JLabel poundsLabel = new JLabel (".lb                                ");
    JLabel ouncesLabel = new JLabel(".oz");
    JTextField idTextField = new JTextField(6);
    JTextField poundsTextField = new JTextField(20);
    JTextField ouncesTextField = new JTextField(20);
    JButton calculateButton = new JButton("Calculate ");
    JTextArea outputTextArea = new JTextArea(4,33);
    JScrollPane outputScrollPane = new JScrollPane(outputTextArea); //For scrollbars around text area
    JLabel totalShippingChargeLabel = new JLabel ("     Total Shippimg Charge: $");
    JLabel totalNumberofPackagesLabel = new JLabel("Total Number of Packages: ");
    JTextField totalShippingChargeTextField = new JTextField(20);
    JTextField totalNumberofPackagesTextField = new JTextField(20);

    Font bigFont = new Font("Times New Roman", Font.BOLD, 28);

    double tsc=0,tnp=0;
    String idb="-1";
    // This is the first method called in a application
//We will create an object of ourselves to call the
//constructor and then set the default close operation for the frame
    public static void main(String[] args)
    {

        ShippingRate basicGUI = new ShippingRate();
        basicGUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }//end of main

    //This is the constructor for this class. It will be called from main
//It will set up our GUI panel with needed components
//and set up appropriate event listening
    public ShippingRate()
    {
//call the superclass' constructor and send a title
        super("Shipping charge calculator");

        companyLabel.setHorizontalAlignment(SwingConstants.CENTER);
        idLabel.setHorizontalAlignment(SwingConstants.CENTER);
//add GUI components to the appropriate container
        mainPanel.add(companyLabel);
        companyLabel.setFont(bigFont);
        companyLabel.setForeground(Color.BLACK);
        mainPanel.add(idLabel);
        mainPanel.add(idTextField);
        mainPanel.add(spaceLabel);
        mainPanel.add(weightLabel);
        mainPanel.add(poundsTextField);
        mainPanel.add(poundsLabel);
        mainPanel.add(ouncesTextField);
        mainPanel.add(ouncesLabel);
        mainPanel.add(calculateButton);
        mainPanel.add(outputScrollPane);
        mainPanel.add(totalShippingChargeLabel);
        mainPanel.add(totalShippingChargeTextField);
        mainPanel.add(totalNumberofPackagesLabel);
        mainPanel.add(totalNumberofPackagesTextField);
        totalNumberofPackagesTextField.setEditable(false);
        totalShippingChargeTextField.setEditable(false);

//add the JPanel to the JFrame
        add(mainPanel);

//call the listeners method
        addListeners();

//set the properties of the JFrame for display
        this.setSize(420, 315);
        this.setVisible(true);
    }//end of constructor

    //Used to register the components to the action listener
    public void addListeners()
    {
        calculateButton.addActionListener(this);
    }

    //Retrieve and convert textfields and calculate and display the gross pay
    public void actionPerformed(ActionEvent e)
    {
        String s1,s2;
        if(e.getSource() == calculateButton)
        {
            String id=idTextField.getText();
            int p = Integer.parseInt(poundsTextField.getText());
            int o = Integer.parseInt(ouncesTextField.getText());
            int to=(16*p)+o;
            double sc=0.12*to;
            sc = sc * 100;
            sc = Math.round(sc);
            sc=sc/100;
            s1="ID Weight Shipping Charge ";
            s2="===================================================";
            outputTextArea.setText(s1+s2+" "+id+" "+p+".lb"+o+".oz"+" "+"$"+sc);
            if(!idb.equals(id))
            {
                tsc = tsc+sc;
                tnp++;
                totalShippingChargeTextField.setText(""+tsc);
                totalNumberofPackagesTextField.setText(""+tnp);
            }
            idb=id;
        }
    }

}//end of class