We (your trusty instructional crew) have already designed a class called BagItems (which you can't see, of course), and it has a static function called get_item(number) where number is an index number from 0 to 19 inclusive.  It will return a string indicating what that item is.  So, you'd call it like this:     item = BagItems.get_item(index_value) where index_value is that index number from 0 to 19 - then item will be what it actually is. Design a class called MysteryBag according to the following instructions:   The class has a fully-mangled static variable called count which keeps a count of the number of bags sold.  Define it as you would any static variable; reference it inside any required method or function of the class by prefixing the name with MysteryBag. - this is necessary due to the name mangling. The class has constructor that chooses five random numbers between 0 and 19, inclusive, and stores these numbers as a list  internally as an instance variable, with full privacy mangling.  This list must be called bag_contents (with this name properly mangled for an instance variable.)  It then increments the static count variable, and then assigns another properly mangled instance variable called bag_number which is the value of count after incrementing. The class also has an function called get_count which returns the static count variable (so, it takes no parameters, not even self, returns the static variable.) The class has a __str__ dunder method that returns the string form of the mystery bag contents, in the following format:   Bag#n: a b c d e where n is the bag number, and a-e are the random items selected (i.e. the strings from BagItems class).  Don't forget to import the random library!  Each line of the output has a newline character after it. NOTE:  on this question, you get five  "free" submissions; after that, you lose 10% of the value of the question per submission (to a minimum of 0, obviously.)  Future tests will have more limitations on your number of tries on code questions.  Remember, you can use your own IDE (PyCharm or IDLE) to test code concepts, even if you don't have all the information available, and it won't impact your "attempts" on Moodle.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

We (your trusty instructional crew) have already designed a class called BagItems (which you can't see, of course), and it has a static function called get_item(number) where number is an index number from 0 to 19 inclusive.  It will return a string indicating what that item is.  So, you'd call it like this:

    item = BagItems.get_item(index_value)

where index_value is that index number from 0 to 19 - then item will be what it actually is.

Design a class called MysteryBag according to the following instructions:

 

  • The class has a fully-mangled static variable called count which keeps a count of the number of bags sold.  Define it as you would any static variable; reference it inside any required method or function of the class by prefixing the name with MysteryBag. - this is necessary due to the name mangling.
  • The class has constructor that chooses five random numbers between 0 and 19, inclusive, and stores these numbers as a list  internally as an instance variable, with full privacy mangling.  This list must be called bag_contents (with this name properly mangled for an instance variable.)  It then increments the static count variable, and then assigns another properly mangled instance variable called bag_number which is the value of count after incrementing.
  • The class also has an function called get_count which returns the static count variable (so, it takes no parameters, not even self, returns the static variable.)
  • The class has a __str__ dunder method that returns the string form of the mystery bag contents, in the following format:

 

Bag#n: a b c d e

where n is the bag number, and a-e are the random items selected (i.e. the strings from BagItems class).  Don't forget to import the random library!  Each line of the output has a newline character after it.

NOTE:  on this question, you get five  "free" submissions; after that, you lose 10% of the value of the question per submission (to a minimum of 0, obviously.)  Future tests will have more limitations on your number of tries on code questions.  Remember, you can use your own IDE (PyCharm or IDLE) to test code concepts, even if you don't have all the information available, and it won't impact your "attempts" on Moodle.

Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education