# Unit 2 Test

Λογισμικό & κατασκευή λογ/κού

15 Αυγ 2012 (πριν από 8 χρόνια και 11 μήνες)

490 εμφανίσεις

GUI Applications

Unit
Test

210

Net Pay Calculator

(It’s time to pay up.)

Create a project in Netbeans and name it the following:

crow(period)_
21
0_(LastNameFirstInitial)

Uncheck the box when asked if you want Netbeans to
create the Main class for y
ou.

You
will NOT be using a Main class in this project. You will, however, turn in the ENTIRE

Introduction
:

Uncle Sam is coming for you and your money!! Remember, we talked about the
following terms earlier this year:

Gros
s Pay:

Your salary before taxes. You might hear someone say, “I make \$40 grand a year.”

Net Pay:

Your

real salary after taxes.
That person bragging about their salary doesn’t really make \$40
grand a year. Taxes take away about 1/4
th
. That person
takes home 3/4ths of their gross.
Their
Net Pay is \$30,000.

Instructions
:

Part 1:

You will create a
GUI Windows application that takes a person’s annual Gross Pay and
then calculates the annual Net Pay, weekly Gross Pay, and weekly Net Pay.

For the p
urposes of this assignment, we will assume that the Net Pay will be 3/4ths of a
person’s gross pay. Also, there are 52 weeks in a year. You should now be able to
calculate the annual Net Pay, weekly Gross Pay, and weekly Net Pay using the
annual
Gross Pa
y.

You need to name your GUI Windows class “NetPayCalculator.” Here is what your
application will look like when you are finished:

The code for this class has been partially completed for you and can be found at the
bottom of t
his document. You will have to finish i
t

and MAKE corrections where
needed.

Part 2:

Once you have created and completed your NetPayCalculator class, you will create
another class called NetPayApplet.

Copy your code from the NetPayCalculator into the Ne
tPayApplet class. You will then
make the necessary adjustments to the code to create an applet.

Compile and run the applet using Netbeans. When you are finished, you should be able
to go to the project’s “build” folder and open the NetPayApplet.html f
dimension of the applet in the HTML file so that it is sized appropriately. Your applet
should look something like this:

Once your
NetPay
Calculator class and
NetPayApplet

class work PERFECTLY, save

CLASS fold
er.

Rubric

210

Net Pay Calculator

Rubric

Points
Available

Points
Earned

NetPayCalculator:
Completed Constructor

(
The
NetPayCalculator class has a constructor that contains the setTitle( ) method, setSize( ) method,
setDefaultCloseOperation( ) method
, add(panel) method, and setVisible( ) method.)

5

NetPayCalculator:
Building A Panel

(
The buildPanel( ) method is complete and correctly builds the jLabels, jTextFields, jButtons, and a panel.
The GUI components are then added to the panel
.)

5

NetPayC
alculator:
Calculate Button Event Listener

(
Th
ere is an event listener for the “Calculate” button that takes the gross annual pay, calculates the net annual
pay, gross weekly pay, and net weekly pay. The appropriate GUI labels are then updated.
)

5

NetP
ayCalculator:
Clear Button Event Listener

(
There is an event listener for the “Clear” button that clears the jTextField and the appropriate labels.)

5

NetPayCalculator:
Static Main Method

(
The NetPayCalculator class con
tains a static Main method that cr
eates an instance of the class when it is
run
.)

5

NetPayApplet

(
Another class called NetPayApplet was created with the code from the NetPayCalculator class. This class
contains an init( ) method and extends the JApplet class. Also this class does not h
ave the methods such as
setTitle( ) , setSize( ), etc…)

5

HTML File

(
The generated HTML file has been altered so that the size of the applet is appropriately displayed within the
web browser.)

5

Java Doc

(
The programmer used
appro
priate
Java Doc
.)

5

(
4
0
)

TOTAL:

Partial
Code for
NetPayCalculator

Class
:

import javax.swing.*;

import java.awt.event.*; //Needed for the ActionListener

import java.text.DecimalF
ormat; //Needed to format as currency

/**

* The NetPayCalculator allows a user to enter their Yearly

* Gross pay and then calculates their Yearly and Weekly Net pay.

*/

public class NetPayCalculator extends JFrame

{

private JPanel panel;

priva
te JLabel jLabel1; //"Enter Gross Pay"

private JLabel jLabel2; //"Estimated Net Pay:"

private JLabel jLabel3; //Estimated Net

private JLabel jLabel4; //"Weekly Gross:"

private JLabel jLabel5; //Weekly Gross

private JLabel jLabel6; //"We
ekly Net"

private JLabel jLabel7; //Weekly Net

private JTextField jTextField1; //Gross Pay

private JButton jButton1; //Calculate

private JButton jButton2; //Clear

private JButton jButton3; //Exit

private final int WINDOW_WIDTH = 500
;

private final int WINDOW_HEIGHT = 700;

/**

* No
-
Argument Constructor that builds the JFrame.

*/

public NetPayCalculator()

{

//Set the window title.

//!!PUT CODE HERE!!

//Set the size of the window

//!!PUT CODE HERE!!

//Specify what happens when the close button is clicked

//!!PUT CODE HERE!!

//Build the panel and add it to the frame.

buildPanel();

//Add the panel to the frame's content pane

//!!P
UT CODE HERE!!

//Display the window

//!!PUT CODE HERE!!

}

/**

* The buildPanel method adds labels, text fields, and buttons to a panel.

*/

private void buildPanel()

{

//Create labels to display instruct
ions

jLabel1 = new JLabel("Enter Gross Pay: ");

jLabel2 = new JLabel("Estimated Net Pay: ");

jLabel3 = new JLabel(" ");

//!!PUT CODE HERE!! Finish Creating the rest of the labels!

//Create a

text field 10 characters wide

//!!PUT CODE HERE!!

//Create a button with the caption "Calculate"

//!!PUT CODE HERE!!

//Add an action listener to the button

//!!PUT CODE HERE!!

//Create a button wi
th the caption "Clear"

//!!PUT CODE HERE!!

//Add an action listener to the button

//!!PUT CODE HERE!!

//Create a button with the caption "Exit"

jButton3 = new JButton("Exit");

r to the button

//Create a JPanel object and let the panel field reference it

//!!PUT CODE HERE!!

//Add the labels, text field, and button components to the panel

//!!PUT CODE HERE!!

}

/**

* CalcButtonListener is an action listener class for the

* Calculate button.

*

* This is an inner private class, which can be created inside another class.

* It's code is only available to th
e class' code.

*/

//private class CalcButtonListener implements ActionListener

//{

//!!PUT CODE HERE!!

//}

private class ExitButtonListener implements ActionListener

{

/**

* The actionPerformed method executes when the user clicks on the

* Exit Button and it closes the program.

* @param e The event object.

*/

public void actionPerformed(ActionEvent e)

{

//Exit the
program

System.exit(0);

}

}

//private class ClearButtonListener implements ActionListener

//{

//!!PUT CODE HERE!!

//}

/**

* This is the main method that lo

*

*/

public static void main(String [] args)

{

//Create an instance of the class here

//!!PUT CODE HERE!!

}

}