Describe a requirement of the program

Assignment Help Software Engineering
Reference no: EM132961550

CSI6208 Programming Principles - Edith Cowan University

Assignment - Programming Project

Background Information

This assignment tests your understanding of and ability to apply the programming concepts we have covered throughout the unit. The concepts covered in the second half of the unit build upon the fundamentals covered in the first half of the unit.

Assignment Overview

You are required to design and implement two related programs:
- "admin.py", a CLI program that allows the user to add, list, search, view and delete nutritional information about fast food menu items, and stores the data in a text file. Develop this program before "foodquiz.py".
- "foodquiz.py", a GUI program that uses the data in the text file to quiz the user about the nutritional information of the fast-food menu items. Develop this program after "admin.py".

The following pages describe the requirements of both programs in detail.

Starter files for both programs are provided along with this assignment brief to help you get started and to facilitate an appropriate program structure. Please use the starter files.

Requirements of "admin.py"
In the following information, numbered points describe a requirement of the program, and bullet points (in italics) are additional details, notes and hints regarding the requirement. Ask your tutor if you do not understand the requirements or would like further information. The requirements are:

1. The first thing the program should do is try to open a file named "data.txt" in read mode, then load the data from the file into a variable named data and then close the file.
» The data in the file should be in JSON format, so you will need to use the "load()" function from the
"json" module to read the data into your program. See the earlier page for details of the structure.
» If any exceptions occur (e.g. due to the file not existing, or it not containing valid JSON data), then simply set the data variable to be an empty list. This will occur the first time the program is run, since the data file will not exist yet. This ensures that you are always left with a list named data.
» This is the first and only time that the program should need to read anything from the file. After this point, the program uses the data variable, which is written to the file whenever a change is made.

2. The program should then print a welcome message and enter an endless loop which starts by printing a list of options: "Choose [a]dd, [l]ist, [s]earch, [v]iew, [d]elete or [q]uit." and then prompts the user to enter their choice. Once a choice has been entered, use an "if/elif" statement to handle each of the different choices (detailed in the following requirements).
» This requirement has been completed for you in the starter file.

3. If the user enters "a" (add), prompt them to enter all 7 details of a fast-food item, beginning with the name. Place the details into a new dictionary with the structure shown earlier, and append the dictionary to the data list. Finally, write the entire data list to the text file in JSON format to save the data.
» Use your "input_something()" function (detailed below) when prompting the user for the name
of the item, to ensure that they are re-prompted until they enter something other than whitespace.
» Use your "input_int()" function (detailed below) when prompting for the nutritional details of the item, to ensure that the user is re-prompted until they enter an integer.
» Your prompts for input should specify that energy is measured in kilojoules, while fat, protein carbohydrates and sugars are measured in grams, and sodium is measured in milligrams.
» Once the dictionary for the new item has been appended to the data list, call your "save_data()" function (detailed below) to write the data to the text file in JSON format.

4. If the user enters "l" (list), print the names of all items in the data list, preceded by their index number plus 1 (so that the list starts from 1 rather than 0).
» If the data list is empty, show a "No items saved" message instead.
» Use a "for" loop to iterate through the items in the data list. Remember: each item is a dictionary.
» You can use the "enumerate()" function to ensure that you have access to variables containing the index number and dictionary of each item as you loop through them (see Lecture 3).

5. If the user enters "s" (search), prompt them for a search term and then list the items that contain the search term in their name. Include the index number plus 1 of the item next to each result. Display search results in the same way that you display items when listing them.
» If the data list is empty, show a "No items saved" message instead of prompting for a search term.
» Use your "input_something()" function (detailed below) when prompting the user for a search term, to ensure that they are re-prompted until they enter something other than whitespace.
» The code to search will be similar to the code used to list, but this time the loop body needs an "if" statement to only list items that contain the search term (use the "in" operator - see Lecture 3).
» Ensure that the searching is not case-sensitive, e.g. "mac" should find an item named "Big Mac".
» If the search term is not found in the name of any items, show a "No results found" message.

6. If the user enters "v" (view), prompt them for an index number and then print the corresponding item's name and all of its nutritional information, including the units of measurement.
» If the data list is empty, show a "No items saved" message instead of prompting for index number.
» Use your "input_int()" function (detailed below) when prompting for an index number, to ensure that the user is re-prompted until they enter an integer.
» Remember: Index numbers shown to/entered by users start from 1, but the data list starts from 0.
» Print an "Invalid index number" message if the index number entered does not exist in the data list.
» When viewing an item, also show the number of calories (rounded up to the nearest whole number) in parentheses after the energy in kilojoules. 1 kilojoule is 0.239 calories.

7. If the user enters "d" (delete), prompt them for an index number and then delete the corresponding item's dictionary from the data list, then print a confirmation message.
» If the data list is empty, show a "No items saved" message instead of prompting for index number.
» Use your "input_int()" function (detailed below) when prompting for an index number, to ensure
that the user is re-prompted until they enter an integer.
» Remember: Index numbers shown to/entered by users start from 1, but the data list starts from 0.
» Print an "Invalid index number" message if the index number entered does not exist in the data list.
» Include the name of the item in the confirmation message, e.g. "Big Mac deleted."
» Once the item has been deleted from the data list, call your "save_data()" function (detailed
below) to write the data to the text file in JSON format.

8. If the user enters "q" (quit), print "Goodbye!" and break out of the loop to end the program.

9. If the user enters anything else, print an "Invalid choice" message (the user will then be re- prompted for a choice on the next iteration of the loop).

Functions in "admin.py"
The requirements above mentioned 3 functions - "input_int()", "input_something()", and "save_data()". As part of "admin.py", you must define and use these functions.

1. The "input_int()" function takes 1 parameter named prompt - a string containing the message to display before waiting for input. The function should repeatedly re-prompt the user (using the prompt parameter) for input until they enter an integer that is greater than or equal to 0. It should then return the value as an integer.
» See Workshop 4 for a task involving the creation of a very similar function.

2. The "input_something()" function takes 1 parameter named prompt - a string containing the message to display before waiting for input. The function should repeatedly re-prompt the user (using the prompt parameter) for input until they enter a value which consists of at least 1 non-whitespace character (i.e. the input cannot be nothing or consist entirely of spaces, tabs, etc.). It should then return the value as a string.
» Use the "strip()" string method on a string to remove whitespace from the start and end.
If a string consists entirely of whitespace, it will have nothing left once you strip the whitespace away.
» Note that exception handling is not needed in this function.

3. The "save_data()" function takes 1 parameter named data_list (the data list from the main program). The function should open "data.txt" in write mode, then write the data_list parameter to the file in JSON format and close the file. This function does not return anything.
» This is the only part of the program that should be writing to the file, and it always overwrites the entire
content of the file with the entirety of the current data.
» See Reading 7.1 for an example of using the "json" module. You can specify an additional indent
parameter in the "dump()" function to format the JSON data nicely in the text file.

The definitions of these functions should be at the start of the program (as they are in the starter file provided), and they should be called where needed in the program. Revise Module 4 if you are uncertain about defining and using functions. Ensure that the functions behave exactly as specified; It is important to adhere to the stated function specifications when working on a programming project.

Constructor of the GUI Class of "foodquiz.py"
The constructor (the " init ()" method) of your GUI class must implement the following:

1. Create the main window of the program and give it a title of "Fast-Food Quiz".
» You are welcome to set other main window settings to make the program look/behave as desired.

2. Try to open the "data.txt" file in read mode and load the JSON data from the file into an attribute named "self.data", and then close the file.
» If any exceptions occur (due to the file not existing, or it not containing valid JSON data), show an error
messagebox with a "Missing/Invalid file" message and call the "destroy()" method on the main window to end the program. Include a "return" statement in the exception handler after destroying the main window to halt the constructor so that the program ends cleanly.
» Once you've loaded the data, check that self.data contains at least 2 items (the minimum needed
for the quiz). If it contains fewer than 2 items, end the program in the same way as described above.

3. Create an attribute named "self.components" and set it to a list containing strings of "energy", "fat", "protein", "carbohydrates", "sugar" and "sodium".
» This will be used in the "show_question()" method to randomly select a nutritional component.
» Make sure that you spell the words exactly the same as the keys of the dictionaries in self.data.

4. Use Label, Button and Frame widgets from the "tkinter" module to implement the GUI depicted on the previous page. The layout is up to you as long as it functions as specified.
» You will save time if you design the GUI and determine exactly which widgets you will need and how to
lay them out before you start writing the code.
» See Reading 9.1 for information regarding various settings that can be applied to widgets to make them appear with the desired padding, colour, size, etc.
» Do not set the text for the buttons that will contain item names at this point. They will be set in the "show_question()" method. See the Discussion Board for help.
» All three of the buttons call the "check_answer()" method when clicked, but each need to pass it a different parameter value - a string of "left", "middle" or "right" (to know which button was clicked). This involves setting the "command" of buttons in a special way. Here is some sample code:

5. Lastly, the constructor should end by calling the "show_question()" method to display the first question in the GUI, and then call "tkinter.mainloop()" to start the main loop.
» To call a method of the class, include "self." at the start, e.g. "self.show_question()".

That is all that the constructor requires. The following pages detail the other methods required, and some optional additions. You are not required to submit pseudocode for "foodquiz.py".

Methods in the GUI class of "foodquiz.py"
This program requires you to define 2 methods to implement the functionality specified - "show_question()" and "check_answer()". These should be defined as part of the GUI class.

1. The "show_question()" method is responsible for randomly selecting two fast-food items and a nutritional component and showing them in the GUI. Simply select two random items from self.data and one random nutritional component from self.components, then use them to set the text for appropriate label and buttons in your GUI.
» This method is called at the end of the constructor to select and show the first question, and at the end
of the "check_answer()" method to select and show the next question.
» Use "random.sample()" to ensure the two items you select from self.data are different. "random.choice()" can be used to select a random nutritional component.
» Store the selected items and the selected nutritional component as attributes (i.e. include "self." at the start of the variable name) so that you can refer to them in the "check_answer()" method.

2. The "check_answer()" method is called when the user clicks one of the buttons. It is responsible for determining whether the user answered correctly and showing an appropriate messagebox, before calling the "show_question()" method to proceed to the next question.
» This method receives a parameter named "choice" that contains a string of "left", "middle" or "right"
depending on which button was clicked.
» If choice is "left" or "right", simply compare the selected nutritional component of the selected items to determine whether the user was correct.
» If choice is "middle", it is correct if the smaller value is at least 90% of the higher value, i.e. if it is
within 10% of it. For example, if the two nutritional values being compared had values of 90 and 100, then the middle button would be correct, but if they had values of 89 and 100 then it would be incorrect.

These methods are all that are required to implement the functionality of the program, but you may write/use additional methods if you feel they improve your program.

Optional Additions and Enhancements for "foodquiz.py"
Below are some suggestions for minor additions and enhancements that you can make to the program to further test and demonstrate your programming ability. They are not required and you can earn full marks in the assignment without implementing them.

- Prominently display the names of the fast-food items being compared in the GUI, using a differently sized or coloured text to make it stand out.
- Consider using "StringVar" objects to control the text of widgets in a more streamlined way.

- Use attributes to keep track of the number of questions that have been asked and how many questions have been answered correctly, and use it to show the users "score" in the GUI.

- Make the messagebox shown after answering a question more informative by including the relevant nutritional information of both items.

- Implement a countdown timer of 6 seconds that is shown on the GUI. If the user does not answer within 6 seconds, show a messagebox saying that they ran out of time and continue to the next question by calling "show_question()". Timers are covered in Reading 9.2.

Attachment:- Programming Principles 1.rar

Reference no: EM132961550

Questions Cloud

Develop a document flowchart : Develop a document flowchart for the following information flow. The individual stores in the Mark Goodwin convenience chain prepare two copies
Calculate the final maturity value : The maturity value is then rolled into another short-term 181-day GIC earning 0.57% simple interest. Calculate the final maturity value
View and delete nutritional information about fast food : View and delete nutritional information about fast food menu items, and stores the data in a text file. Develop this program before "foodquiz.py"
How many additional hours of labor would the contractor hire : How many additional hours of labor would the contractor hire if they were offered a $3000, $4000, and $5000 on-time completion bonus
Describe a requirement of the program : Describe a requirement of the program, and bullet points (in italics) are additional details, notes and hints regarding the requirement
CSI6208 Programming Principles Assignment : CSI6208 Programming Principles Assignment Help and Solution, Edith Cowan University - Assessment Writing Service - Understanding of and ability
What will your ipo price per share be : Assuming that your IPO is set at a price that implies a similar multiple, what will your IPO price per share be
What is a good use for a compound key : What is a good use for a compound key and Write an SQL query that would return the first and last names of each user in a "users" table that have the password
What is a state machine : What is a state machine and Describe the difference between an "Aggregation" relationship and a "Composition" relationship in a UML class diagram.

Reviews

Write a Review

Software Engineering Questions & Answers

  How accessible the source code is to the general public

Some other notable differences between open source and commercial software are how accessible the source code is to the general public

  Why is the waterfall model of software engineering the most

Why is the waterfall model of software engineering the most commonly used method for development of trusted systems?

  Identify the data type for variable

Assume you manage a dog walking service, in which you interact with both clients and dog walkers. Your task is to schedule dog-walking appointments based on the customers requested dates and times and the availability of the dog walkers.

  Question 1a why is it imperative to use systems analysis

question 1a why is it imperative to use systems analysis and design methodologies when building a system?b describe how

  Why is an association class used for a class diagram

Why is an association class used for a class diagram? Give an example of an association class that may be found in a class diagram that captures students and the courses that they have taken.

  Describe two of the architectures

1.Describe two of the architectures from below. What do they support? Do they have any shortcomings? 1) Monolithic 2) 2-Tier 3) 3-Tier

  Importance of professional looking worksheets

Discuss and explain in Excel why is it important to have a professional looking worksheet? Why spend so much time with styles and formats and creating borders?

  Explain the three main ways to apply css styles

Explain what a class selector is and how it's used: Explain the three main ways to apply CSS styles to a Web page:

  Quality building supply qbs has proposed a project to

quality building supply qbs has proposed a project to develop a business system.the project team has gathered the

  Draw the sequence diagram step by step to withdrawal money

Draw the sequence diagram step by step to withdrawal money considering four objects Patron, ATM, Control and database for ATM process.

  Determine various project milestones that are within project

determine the various project milestones that are within the project. Describe the review process that will take place at each of these milestones.

  What do you think is the most appropriate life cycle

What do you think is the most Appropriate Life Cycle Approach from X_tream programming,Spiral or incremental What is the advantage of this approach for this project?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd