The purpose of this assessment item is to assess your skills attributable to the following learning outcomes and achieving the expected graduate attributes of advanced level knowledge, cognitive, technical, and creative skills, and self-management.
Compare and contrast different algorithms in problem solving
Design and implement appropriate data structures for application development
Evaluate a variety of data structures and algorithmic approaches including: recursion, linked lists, stacks, queues, streams, search trees, sorting and searching
Analyse, develop and implement software solutions with the focus of data structures and algorithms
Apply classes, inheritance, polymorphism, and exception handling
Programmatically connect to a database and implement the database operations Work collaboratively as part of a small team
Demonstrate socially innovative practices in software development
Your task in this assessment is to analyse the given problem, model, and design the required data structures using UML class diagrams. You will be implementing the software solution, applying efficient algorithms, inheritance, polymorphism, database programming, and exception handling. You will be using variety of data structures and algorithms in your solution design. The topics required for this assessment task are from Weeks 1-10. Your Java Application should have an interactive Graphical User Interface (GUI) based on the JFrame class using SWING GUI components. Your application will connect to a database programmatically, executing necessary SQL queries within your java program.
You should also write an individual report, as specified in this document, demonstrating your conceptual knowledge and communication skills.
2.1 Problem
This is an extension to the problem given in Assessment Item 1 as specified here. Statistical data show that ready-to-eat (RTE) cereals account for the bulk (78.5%) of all breakfast foods. Often, fresh juice is accompanied by the breakfast cereals. A large variety, approximately over 4900, of products exist in the breakfast cereal category which widely varies in their nutrient content. Even though a nutrition panel with nutrition information is provided on the pack, it is very difficult for a consumer to make an informed decision quickly to choose a comparatively healthier product. Therefore, a processed food suitability assessor (PFSA) is suggested, which can enable consumers to make informed decision making on their choice of processed food items. The initial prototype you have designed for the PFSA has very limited functionality of displaying items and nutrition information of selected items. In this Assessment, you have to extend the prototype developed as part of your first Assessment to a functional application that can be released as a beta version for initial testing
You are given a .csv file named processedFoodData.csv (available at the Unit website) with necessary data that can be used. The file includes a list of RTE breakfast cereals and beverages. The processed food details available in the file include:
1. Item name
2. Category
3. Serve size
4. Unit of serve size
5. Amount of energy in kilo joules
6. Amounts of protein, fat, carbohydrate, sugar, and dietary fibre in grams/per serve
7. Amount of sodium in milligrams per serve.
The users accessing the PFSA should be provided the following functionality
1. Load the data from the .csv file and save the list to a database (only for the first time).
2. Load the data from the database to a Linked List
3. Choose the preference of listing the items sorted by High Protein or Low Sugar
4. Display the sorted list of food and beverage in two .ListBoxes
5. Choose multiple items of food and Beverage from the ListBoxes and save them to the data base.
6. Display the nutrition information of the selected items in the TextArea.
The PFSA should allow the User to enter name in a TextField and choose one of the preferences of High Protein or Low Sugar using RadioButtons. Once the User has chosen the preference the ListBoxes should display the sorted names of Food and Beverage items.
The User can then select multiple Food and Beverage items and save these choices to the database.
2.2 Design Guidelines
You can use the following guidelines in your modelling and GUI design.
The application should have a GUI for user interactions. This GUI should have the necessary components to enable the user to execute all the functions as provided in Section 2.1 above. You may use the guidelines provided below for your GUI design and implementation. Variations to the provided guidelines are acceptable as long as it meets the user requirements.
i) Top Panel
The top panel can have a Label and TextField, to display the label 'User Name' and enable the user to enter the name in the TextField. The second row of the top panel can have a Label to display Choose your preference and two RadioButtons for the choice of High Protein and Low Sugar.
The third row of the top panel can have the two ListBoxes (JList)
ii) Middle Panel
This panel can have a TextArea to display welcome message to the User and the food choices and nutrition values.
iii) Bottom Panel
This Panel can have a label "Command Buttons" and can contain the required Command Buttons of 'Display Choices' Save Selections, Clear Display and Quit.
A full GUI design diagram is not given to encourage you to design using your own colour choices and other attributes for the GUI components.
Initialisation
Your application should start by loading the data from the data file and saving the data to the database only for the first time. If the database exists and contains records, then the program need not load data from the file. Rather, the application should load the data from the database.
The functions of the four Command Buttons are given below.
The user enters the name using the TextField. Then a welcome message should be displayed to the user.
An example display is shown below. You can design and choose your own wordings for the message to make it user friendly.
Hello Mary Welcome to Processed Food Assessor System
Select your preference of ‘High Protein’ or ‘Low Sugar’ Use
ctl+click to select multiple items from the displayed List Use
the DisplayChoices button to view details of your choices
You should also display appropriate error messages
Display Choices Button
The user clicks this button to view the details of the food and beverage chosen using the ListBoxes. Display appropriate error messages if the user clicks this button before choosing items or preferences.
An example display is shown below. see image.
Save Selections Button
Clicking this button should save the user's selections to the database. As the database already contains the food and user details you need to save only the food Id and user Id to a table.
Clear Display Button
Clicking on the "Clear Display" button should clear all contents from the TextArea, the TextField.
Quit
The "Quit" button should allow the user to exit from the application.
You may follow the class design given below. You should read the specification carefully and design the classes using UML class diagrams and include the attributes with correct data types and all the methods, clearly indicating public or private. Clarify your doubts during the design stage so that your implementation can be less error prone and faster to complete.
You can use classes from your own Assignment One solution or from Assignment One solution provided on the Unit website. But you should understand the code and make necessary changes
i) Item class (same as Assignment 1)
This is a generic class and include appropriate fields to store:
an itemName
a category.
This class should have:
a parameterised constructor, accessor, mutator methods,
a toString() method.
ii) Nutrient class (same as Assignment 1)
This class stores the:
nutrient name
nutrient amount.
This class should have:
a parameterised constructor, accessor, mutator methods, and
a toString() method.
iii) DataFile class (same as Assignment 1)
This class will have a parameterised constructor that takes the filename to be processed.
Include an ArrayList< > type attribute to read and load the data from the file.
Include a method to load data from the given file named 'processedFoodData.csv' available from the Unit website and return the ArrayList< >.
Use necessary file handing exceptions.
iv) ProcessedFood class (modified)
This class extends the Item class.
In addition to the inherited attributes, this class stores:
the foodId (this can be empty while reading data from the file, but use to store the foodId from the database.)
serve size,
serve unit (gm, or ml)
an ArrayList of Nutrient objects to store the nutrient details.
This class should have a parameterised constructor, copy constructor, a default constructor, accessor, mutator methods, and a toString() method.
v) DatabaseUtility class
This class should have the following attributes.
Databse url name
sqlConnection
username
password
foodList to store and return the ProcessedFood data.
This class should have
a constructor to set values to the attributes and connect to the database.
A method to create the Database tables executing the sql queries.
Method to insert all the ProcessedFood data.
Method to insert the User Data
Method to insert the UserId and foodId for the User's food choices.
Method to insert the Nutrient details for the food
Method to read data from the database and return the ProcessedFood details
You should use PreparedStatements in the above methods to insert values into the database or read values from the database.
vi) ProcessFoodGUI class
This class should have all the GUI components as described under the Graphical User Interface Design section. This class will initialize the GUI components and will have the event handling methods for enabling the appropriate user interactions.
This class stores the data file name, creates the DataFile object and invokes its method to read and load the data from the file. This class creates a DatabaseUtility object and invokes appropriate methods for completing the user required functions. This class will have a userName attribute to store the entered user name. This class also will have the main method and starts the application.
Vii Database
You can use the following guidelines to design your database tables.
Tables
1. Food: to store the foodId, foodType, name, serveSize, and serveUnit
2. Nutrient: to store the nutrientId, name, value. One Food item has many nutrients (many to one) so you have to use a foreign key
3. User: to store the userId, and name
4. User_food: to store the userId and foodId ( many to many relationship exists between user and food as one user can select many food items and one food item can be chosen by many users.)
Note:The primary keys are generated during the programmatic creation of the tables and used for other database operations. The primary keys can be auto-incremented integer values. Create an ERD to understand the relationship between tables.
You can use a Sql query to initialize the auto-incremented primary key value to a specific number.
Example: TABLE_SET_FIRST_FOOD_ID = "ALTER TABLE FOOD AUTO_INCREMENT = 1001";
Exceute the query as shown below after executing the query to create Table. statement.executeUpdate(TABLE_SET_FIRST_FOOD_ID);
Include necessary accessor, mutator methods, constructors, and toString() method for each class. Also, follow good coding practices, using meaningful names, camel case notation for naming, constants as necessary, and include meaningful comments. You can use NetBeans to develop your application.
Data: The data required is available in the file named 'processedFoodData.csv' available at the Unit website under the Assessment folder on the top of the page. This is a text file and you can use text file processing to load the file.
You should submit a report containing the following details.
1. UML class diagrams for the classes
2. Test plan showing input data, expected results, and actual results
3. Write your suggestions on future modifications to the PFSA so that people can use it to select healthier food choices. This can be suggestions on the GUI to promote the choice of healthy items.