Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You will write a program which will perform a filtering action. In your program you will get the name of the JSON file as an

You will write a program which will perform a filtering action. In your program you will get the name of the JSON file as an input from the user. If file exist, proceed to prompt more options, otherwise let user know file was not found, let user re enter, until user presses Q (q is exit). If file exist, prompt the user with the filtering options. User can also choose to save new filtered data in separate file.
Prompt user to give you name of the JSON file. JSON object will have these keys - id, first_name, last_name, age, city, phone_number
You can always assume, JSON file will have data and it will be in the same format shown above.
For testing purposes use the following file: data.JSONDownload data.JSON
If file was found, proceed to show these filtering options.
1. filter by age
a. user must enter min and max age, show all rows that have age between min and max including the min and max number.
b. if user entered the same number for min and max, that means user is looking specifically for that age
c. you must do checking where min shouldn't be greater than max. And min cannot be less than 0.
2. filter by city
a. once user enters city, present with all data that matches the city name, if none exist, just show a message saying no data found.
3. filter by last name
a. once user enters last name, present with all data that matches the last name, if none exist, just show a message saying no data found.
4. filter by first name
a. once user enters first name, present with all data that matches the first name, if none exist, just show a message saying no data found.
5. filter by id
a. same rules like age but with id instead.
Q to quit.
If data was filtered, give user an option to save filtered data.
User.py Requirements
Must include all variables and all variables must be private - id, first_name, last_name, age, city, phone_number
Must include constructor accepting all variables above.
Must include getters and setter for all variables.
Must have an overriden __str__() function to print User info in the same format required by the assignment. (example output below)
Must have a function called - in_range(min, max)
in_range - will take min and max numbers then return true if age is within the limit, or return false if it is not.
Sample output:
Please enter JSON file name (or Q to exit): test
File was not found.
Please enter JSON file name (or Q to exit): data.JSON
File found.
Here are your filtering options:
1- Filter by age (min and max)
2- Filter by city
3- Filter by last name
4- Filter by first name
5- Filter by id (min and max)
or enter Q to quit
1
Please give min age for filtering: 18
Please give max age for filtering: 17
Max cannot be less than min!
Please give max age for filtering: 21
Here is the filtered data based on age between 18 and 21 inclusively.
User ID: 0
Alex Anderson
Omaha, NE
21
402-123-4567
-----------------
User ID: 13
Seth Green
Denver, CO
19
402-233-3232
(If no data was found, print a message saying no data was found, then move on to asking about going back to the main menu)
Would you like to save the filtered data? Y/N
Y
What should the name of the new file be?
filtered_age
Your filtered data was saved in filtered_age.JSON <-- this must output a file with filtered data above saved in the same format as the original data.
Would you like to go back to the main menu? Y/N
N
Terminating program. Good bye!
---------------------------------------
There is a lot of repetitive functionality in this assignment, I am expecting you to be very efficient with your solutions. Utilize for loop, while loop and functions to reuse your code.
Your submission MUST include these file:
User.py - Must satisfy all requirements mentioned above.
main.py - must have main function in it. Failure to include main function in your submission will result in 0.
You can include more classes or functions if you would like, but these are minimum requirements.
Main function Ex:
def main():
# your logic here
if __name__=="__main__":
main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions