This assessment item relates to the course learning outcomes as stated in the Unit Profile.


For this assignment, you are required to develop a Windowed GUI Java Program to demonstrate you can use Java constructs including input/output via a GUI interface, Java primitive and built-in types, Java defined objects, arrays, selection and looping statements and various other Java commands. Your program must produce the correct results.

The code for the GUI interface is supplied and is available on the course website, you must write the underlying code to implement the program. The command buttons are linked to appropriate methods in the given code. Please spend a bit of time looking at the given code to familiarise yourself with it and where you have to complete the code. You will need to write comments in the supplied code as well as your own additions.

What to submit for this assignment

The Java source code:
You will need to submit two source files: and, please submit these files

as a single zip file, do not include your report in the zip file you must submit it as a separate file.

If you submit the source code with an incorrect name you will lose marks.

A report including an UML diagram of your Tax class (see text p 493), how long it took to create the whole program, any problems encountered and screen shots of the output produced. (Use Alt-PrtScrn to capture just the application window and you can paste it into your Word document) You should test every possibility in the program.

o ReportAss2.docx
You will submit your files by the due date using the “Assignment 2” link on the Moodle course

website under Assessment … Assignment 2 Submission.

Due date:

Weighting: Length:


Assignment Specification

In assignment one we read in multiple tax payer names and incomes using both Scanner and GUI dialogs. In this assignment we are going to read in the data and output information via a GUI interface, the code for the GUI interface is supplied (via the Moodle web site) which supplies the basic functionality of the interface. We are also going to store the information in an array of Tax objects.

Look at the code supplied and trace the execution and you will see the buttons are linked to blank methods (stubs) which you will implement the various choices via the buttons.

The GUI interface contains two JLabels for the prompts.
There are two JTextFields in which the tax payer name and income are read.
Four JButtons are after the income JTextField which link to blank methods for implementing the functionality of the application.
There is also a JTextArea for displaying the output.

Tax Class

First step is to create a class called Tax ( it will not contain a main method.

The Tax class will be very simple it will contain two private instance variables: o taxPayerNameasaString
o incomeasaninteger

The following public methods will have to be implemented: o Adefaultconstructor
o Aparameterisedconstructor
o Twosetmethods(mutators)

o Twogetmethods(accessors) o computeTax()method*

*You will also create a public value returning method to return the calculated tax. The tax can be derived from the calculation according to the tax rates as assignment 1. In other words the tax will be retrieved via your computeTax() method, which is a user-defined method inside the Tax class and it does not contain the keyword static.

TaxGUI class

Once the Tax class is implemented and fully tested we can now start to implement the functionality of the GUI interface.

Data structures

For this assignment we are going to store the tax payer names and incomes in an array of Tax objects. Do not use the ArrayList data structure.
Declare an array of Tax objects as an instance variable inside the TaxGUI class, the array should hold ten entries. Use a constant for the maximum entries allowed.

private Tax [] taxArray = new Tax[MAX_ITEMS];

We need another instance variable (integer) to keep track of the number of the tax payer being entered and use this for the index into the array of Tax objects.

private int currentPayer = 0;

Button options
1. Enter button: enterData()
For assignment two we are going to use the JTextFields for our input.

When the Enter button is pushed the program will transfer to the method: enterData(), this is where we read the tax payer name and income and add them to the Tax array.

The text in the JTextFields is retrieved using the getText() method:

String taxPayerName = nameField.getText();

When we read the income input we are reading a string from the GUI, we will need to convert this to an integer using the Integer wrapper class as per assignment one.

int income = Integer.parseInt(incomeField.getText());

We need to add these values of name and income to the array of Tax objects, when we declared our array using the new keyword, only an array of references were created, we need to create an instance of each of the Tax objects. When we create the Tax object we can pass the name and income to the object via the parameterised constructor.

taxArray[currentPayer] = new Tax(taxPayerName, income); Remember to increment currentPayer at the end of the enterData () method.

Alternatively, you can use the setTaxPayerName( ) and setIncome( ) methods to a Tax object. Next we will output the entry including the tax in the JTextArea

The supplied code may contain the methods for printing the heading and the line underneath.
Just like the JTextFields the JTextArea has a method setText() to set the text in the text area, note this overwrites the contents of the text area.

When the data has been entered and displayed, the name and income JTextFields should be cleared. We can clear the contents by using: textField.setText(“”);

The focus should then return to the tax payer name JTextField. nameField.requestFocus();

Data validation (you can implement this after you have got the basic functionality implemented) If one or two textField has not been entered data and the ‘Enter’ button is clicked, your program

should pop up a message box to remind user the required input.
Use an if statement at the beginning of the method and after displaying the error dialog use the

return statement to exit the method.

if (nameField.getText().compareTo("") == 0) // true when blank

Use the above code to check the name field for text if there is no text display the following error dialog and use the return statement to exit the method, the focus should return to the name field.

The income field should also be checked for text.

We will not worry about checking data types or numeric ranges in this assignment.

2. Display all tax payer names, incomes and taxes: displayAll()
When this option is selected, display all of the tax payer names and incomes plus the taxes which have

been entered so far. At the end of the list display the number of entries and the maximum tax value.

Use a loop structure to iterate through the array, you should be sharing the printing functionality with the enter button, hint: create a method which prints one tax payer name, income and tax entry and use this throughout the program.

Only print the entries which have been entered so far and not the whole array, use your instance variable currentPayer as the termination value in your loop.

Inside the loop, use an if statement to compare the assumed maximum tax value with the tax value retrieved from the compuetTax () method. In the text area display the maximum of tax value.

If no entries have been added clear the text area and display the following error dialog, repeat this for your search.

COIT11222, Assignment Two, 2017 Term Two – Page 7 of 11

3. Search for a tax payer name: search()
You can just use a simple linear search which will be case insensitive. Use the JOptionPane.showInputDialog() method to input the tax payer name.

If the search is successful display the details about the tax payer.

If the search is unsuccessful display an appropriate message and clear the text area.

4. Exit the application: exit()
The exit method is called when the user pushes the exit button or when they select the system close (X

at top right hand corner), try and find the code which does this.

During a typical exiting process we may want to ask the user if they want to save any files they have open or if they really want to exit, in this assignment we will just print an exit message.

Extra Hints

Your program should be well laid out, commented and uses appropriate and consistent names (camel notation) for all variables, methods and objects.

Ensure you have header comments in both source files, include name, ID, filename, date and purpose of the class.

Make sure you have no repeated code (even writing headings and lines in the output)

Constants must be used for all literal numbers in your code (computeTax method).

Look at the marking criteria to ensure you have completed all of the necessary items

Refer to a Java reference textbook and the course and lecture material (available on the course web site) for further information about the Java programming topics required to complete this assignment.

Check output, check code and add all of your comments, complete report and the UML class diagram.

Supplied Code

Download, compile and run the supplied code available from the course web site.
You will see the GUI interface has been implemented and you have to implement the underlying code, use the supplied method stubs and add you own methods. Look for // ToDo comments in the code which contain hints.

Related posts: