Assignment Specification

You have completed the console program for the Rocky Fruit & Vegetable Market. The boss wants a GUI prototype of the program to allow staff to enter purchases of fruit and vegetables for customers. You are to write a Java GUI Application (FruitVegShopGUI class). Most of the GUI code has been written and it looks like this: See image.

The name of the customer is to be entered in to the name text field, produce will be selected from the drop down combo box and the kilograms of the purchase will be entered into the enter kilos textfield.

Your job is to implement the enter button and each one of the buttons along the bottom.

Enter

When the user hits the Enter button the information about the current purchase will be displayed (very similar to assignment one), for example: See image.

Use displayTextArea.setText() to over write the contents of the text area and displayTextArea.append() to append text. Use String.format() as it is identical to printf in functionality which you used in the first assignment.

You will use four parallel arrays to store the name of the purchase, the weight of the purchase, the cost per kilogram and the cost of the purchase, a maximum of twenty purchases should be set.

If the limit is reached report this with an appropriate message dialog: See image.

If no customer name is entered do not add the details of the purchase and report the error: See image.

If no weight is entered again do not add the details of the purchase and report the error: See image.

Note: In an actual working program the application would be connected to an electronic scale and the weight would be retrieved from that.

Retrieving the produce name and produce cost per kilogram

The functionality of the dropdown combo box containing the produce names has been implemented for you, and you will notice the label containing the label is automatically updated when a different produce item is selected.

You can get the index of the combo box selection by using:

int selectedIndex = produceCombo.getSelectedIndex();

You can now use this index to access the produceNames and producePrices arrays which have been supplied to update your four parallel arrays.

When the produce details have been successfully entered and displayed the enterKgField must be cleared, and of course the class instance variable numberOfPurchases (supplied) will be incremented.

The variable numberOfPurchases is what you will use to write the details of the purchase to the parallel arrays (as the index).

Display Al

This option will display the customer name, all purchases entered so far and the total cost. Use a loop to print the elements of the four parallel arrays.

The text area is set to a mono-spaced font so String.format can be used to align the columns. See image.

New

When this button is selected we are going to process a new customer. You will need to set numberOfPurchases and totalCost to zero, clear the displayTextArea, nameField and enterKgField. (hint use: enterKgField.setText();etc)

Also use produceCombo.setSelectedIndex(0); to reset the combo back to the first entry.

Search

When search is selected the program will receive the produce name to search for via an input dialog box. You can just use a simple linear search which will be case insensitive. See image.

If the search is successful display the details about the purchase. See image.

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

Sort by name

This option will sort the produce list in the combo by name. See image.

You must use a sort method which has two loops; you cannot use the inbuilt sort method within Java Arrays class as you will need to sort the two supplied lists produceNames and producePrices in tandem using the name list as the sort criteria. Ignore the case of the strings in order to sort the lists alphabetically instead of lexicographically.

Once the supplied lists have been sorted the supplied method rePopulateCombo() is called to repopulate the combo box, this call is included in the sort method stubs supplied.

Sort by price

This option will sort the produce list in the combo by price cheapest to most expensive. See image.

Here we use the prices list as the sort criteria.

Exit

When the user selects this option the program will ask the user if they really want to Exit. See image.

For this use the showConfirmDialog in JOptionPane. If the user selects yes which is equal to (JOptionPane.YES_OPTION) then exit the program, otherwise just ignore it and return to the program.

Extra Hints

Use nameField.getText() to retrieve the name of the customer, use nameField.setText() to clear the name field.

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

Make sure you have no repeated code (even drawing the line in the output) You cannot use a list of objects you must use four parallel lists.

Constants must be used for all numbers in your code.

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 activity diagram.

Supplied GUI Code

Download, compile and run the supplied GUI code available from the course web site. You will see the GUI interface has been implemented using various panels and layout managers. Study the code to understand how it works, you can experiment and change things around, but preserve an original copy of the code for your assignment.

You have to implement the underlying code, use the supplied method stubs and add you own methods.

Again no code should be repeated in your program.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.