Create a class with the following features: i. This class will represent a restaurant picker, so name it appropriately.

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Create a class with the following features: i. This class will represent a restaurant picker, so name it appropriately.

Post by answerhappygod »

Create a class with the following features:
i. This class will represent a restaurant picker, so name it
appropriately.
ii. This class must have the following default functions:
1. __init__
2. __str__
3. __repr__
4. Accessors for each attribute
5. Mutators for each attribute
iii. This class must have the following attributes:
1. catalog: Default to an empty list
2. cache: Default to an empty list
iv. This class must have the following custom functions:
1. addToCache
a. It accepts a restaurant for a parameter
b. It appends the parameter to the object’s cache list
2. chooseRandomly
a. It accepts a number of choices for a parameter
b. Create a variable to hold the choices and set it to an empty
list
c. Create a variable to act as a counter and set it to 50
d. Loop while the length of choices is less than the parameter
and while the counter is greater than zero. For every iteration of
the loop:
i. Call the object’s getRandomChoice function (defined below)
and store the result in a variable.
ii. If the item is not already in the cache list, then:
1. Append it to the choices list
2. Append it to the cache list using the addToCache
function.
iii. Decrement your counter by 1
e. Use the object’s mutator to set the cache list to be the same
as the choices.
f. Call the object’s saveCache function (defined below)
g. Return the choices variable
3. getRandomChoice
a. No additional parameters needed.
b. Use the random library’s choice function to pick a restaurant
from the object’s catalog (see 4.05 for details on the random
library).
c. Return the choice
4. loadCache:
a. It should try to load the cache filename as JSON data and
store the result in the object’s cache attribute.
b. If it can’t load the data into the cache variable (hint:
exception handling), then it should set the cache to be an empty
list.
5. saveCache:
a. It should use the JSON library’s functionality to try to dump
the cache into the cache filename.
b. If it can’t save the cache, it should just quietly ignore any
error. Hint: Use the pass statement.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply