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: Tax.java and TaxGUI.java, 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.
You will submit your files by the due date using the “Assignment 2” link on the Moodle course
website under Assessment … Assignment 2 Submission.
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.
The Tax class will be very simple it will contain two private instance variables: o taxPayerNameasaString
The following public methods will have to be implemented: o Adefaultconstructor
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.
Once the Tax class is implemented and fully tested we can now start to implement the functionality of the GUI interface.
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;
1. Enter button: enterData()
For assignment two we are going to use the JTextFields for our input.
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.
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();
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.
When this option is selected, display all of the tax payer names and incomes plus the taxes which have
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.
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.
The exit method is called when the user pushes the exit button or when they select the system close (X
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.
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.
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.