Question

In: Computer Science

Scenario Suppose you are designing a piece of software for a packaging company. A part of...

Scenario

Suppose you are designing a piece of software for a packaging company. A part of the software involves an items capacity limit mechanism to prevent a package from being shipped when it's filled past its capacity.

Aim

Define a class called Package, which will have a maximum item capacity of 6.

  • The package should be initialized with the number of items.
  • If the number of items exceeds the capacity limit during initialization, it should print out a message indicating that the limit has been exceeded and only initialize how many items should be removed from the package.
  • Otherwise, if the number of items does not exceed the limit, it should print out a message that includes how many items are in the package.

Our aim here is to practice creating class attributes.

Steps for Completion

  1. Go to you main.py file.

  2. In the space provided, declare the Package class by adding an items limit class attribute.

  3. Add the initializer, which will check whether the item limit will be exceeded, and print a message indicating how many items must be removed.

  4. If the items limit has not been exceeded, print out the number of items in the package.

  5. Finally, create a while loop that requests the user to input the number of items and then asks if we'd like to continue.

  6. Create a few instances of the class declaration to test your implementation, Snippet 7.46 shows an example:

package1 = Package(6)
print("There are", package1.items, "items in the package being shipped out.")
package2 = Package(10)
print("There are", package2.items, "items in the package being shipped out.")

Snippet 7.46

Run the script by running the python3 main.py command in the terminal. The output should look similar to Figure 7.3:

Figure 7.3

Grading

Complete each task listed below. Each task contains automated checks which are used to calculate your grade. When you have completed each task by clicking the checkbox, open the task list panel on the left navigation bar and click the "Submit" button.

Task

Define a class called Package that has a maximum capacity of 6 items and prints out a message indicating that the limit has been exceeded and how many items must be removed from the package.

Solutions

Expert Solution

The Python 3 Code is given below. Kindly copy the code and paste into the ide and run it to see the results. If you have any issues then comment in the comments section and kindly give a thumbs up if you liked the answer.

##################################################################
#           Class Package Definition starts here                 #
##################################################################

class Package:

  # Class attribute to store the maximum limit of
  # the items that can be shipped in a Package
  MAX_ITEM_CAPACITY = 6

  # Function to initialize the number of items
  # and to test for exceeding capacity of the items
  def __init__(self, num_items):
    
    self.__NumItems__ = 0 # attribute to store the number of items

    # check if number of items to be shipped does not exceeds the limit
    if(num_items > Package.MAX_ITEM_CAPACITY):
      # if exceeds then calculate the difference
      diff = num_items - Package.MAX_ITEM_CAPACITY
      # print the messa ge and difference
      print('The maximum item limit has been exceeded.')
      print('%d items must be removed from the package.'%(diff))

    # else print the shipping message  
    else:
      self.__NumItems__ = num_items
      print('There are %d items in the package being shipped out.'%(self.__NumItems__))


##################################################################
#           Class Package Definition ends here                   #
##################################################################



# declare choice variable for inputting more items to be shipped
choice = 'y'

# loop untill choice is y or Y
while(choice == 'y' or choice == 'Y'):
  # get number of items to be shipped
  num_items = int(input('How many items are in the package? '))
  
  # create a Package object sending it to, the number of items
  # to be shipped
  my_package = Package(num_items)
  
  # ask whether to ship more or not
  choice = input('Ship more packages?(Y/N) ')

Code Screenshot

CONSOLE OUTPUT

Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 22:45:29) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> 
========== RESTART: C:/Program Workspace/Python 3 Workspace/Package.py =========
How many items are in the package? 7
The maximum item limit has been exceeded.
1 items must be removed from the package.
Ship more packages?(Y/N) y
How many items are in the package? 8
The maximum item limit has been exceeded.
2 items must be removed from the package.
Ship more packages?(Y/N) Y
How many items are in the package? 3
There are 3 items in the package being shipped out.
Ship more packages?(Y/N) N
>>> 

Related Solutions

Suppose that you are working as part of a team designing a network for XYZ high...
Suppose that you are working as part of a team designing a network for XYZ high school. Consider that the school has six departments, Admin, Academic, Human Resource (HR), Finance, IT support and Sports. 1. Analyse the project hardware requirements along with the number of devices and cost. 2. Justify the approach you would be taking to design the network for the school. 3. Using the network simulator (such as packet tracer) design the network. 4. Illustrate the network configuration...
Suppose that you are working as part of a team designing a network for XYZ high...
Suppose that you are working as part of a team designing a network for XYZ high school. Consider that the school has six departments, Admin, Academic, Human Resource (HR), Finance, IT support and Sports. 1. Analyse the project hardware requirements along with the number of devices and cost. [3 Marks] 2. Justify the approach you would be taking to design the network for the school. [3 Marks] 3. Using the network simulator (such as packet tracer) design the network. [4...
Imagine that you are part of the management team for Econsoft, a computer software company. You...
Imagine that you are part of the management team for Econsoft, a computer software company. You are discussing one of your products, “Econblaster,” with the company’s CEO and the other managers. You have made the software available for download on your firm’s website for download for $9.99 and you are trying to figure out how to generate more revenue from the product. Half of the management team suggests increasing the price to $11.99. The other half advocates cutting the price...
You are part of a team responsible for designing an assessment to determine whether or not...
You are part of a team responsible for designing an assessment to determine whether or not your company’s information security controls are in compliance and to identify any necessary improvements or adjustments. Select two of the aspects listed below and discuss the importance of each in establishing a successful security metrics program. Give specific examples. What problems/issues might your company face if those aspects are not handled appropriately? Identifying stakeholders Defining metrics program goals and objectives Deciding which metrics to...
PSEUDOCODE: 1. You are designing software for a voting booth. Please create pseudocode for a modular...
PSEUDOCODE: 1. You are designing software for a voting booth. Please create pseudocode for a modular program that: - Takes in a user inputted integer for age. If their age is below 18, display "you are too young to vote" - Only If their age is high enough, please ask them which candidate they wish to vote for. Valid options are "dog", "cat", "horse" - If they did not choose a valid option display "you did not choose a valid...
Part A Scenario A: You are an investment performance analyst for a fund management company. After...
Part A Scenario A: You are an investment performance analyst for a fund management company. After providing client account investment performance reports to the client-facing departments, you notice the reporting system missed a trade. These reports have not been finalised and released to clients. Correcting the omission in the report will result in a huge loss for a client. This client had previously expressed concern about the under-performance of its funds under your firm’s management and expressed that it may...
Part 1 (30 marks) IT Software Project As a senior analyst for the company you have...
Part 1 IT Software Project As a senior analyst for the company you have been asked to evaluate a new IT software project. The company has just paid a consulting firm $50,000 for a test marketing analysis. After looking at the project plan, you anticipate that the project will need to acquire computer hardware for a cost of $400,000. The Australian Taxation Office rules allow an effective life for the computer hardware of five years. The equipment can be depreciated...
Scenario: you are designing PlayMe.io – a mobile app to enter, manage, and play music playlists....
Scenario: you are designing PlayMe.io – a mobile app to enter, manage, and play music playlists. Using simple block diagram to show the architecture of the system. Pick an architectural pattern to use for PlayMe.io. Explain the rationale of its use, advantages, and potential pitfalls.
Suppose you are a high-level manager in a software firm and you are managing n software...
Suppose you are a high-level manager in a software firm and you are managing n software projects. You are asked to assign m of the programmers in your firm among these n projects. Assume that all of the programmers are equally competent. After some careful thought, you have figured out how much benefit i programmers will bring to project j. View this benefit as a number. Formally put, for each project j, you have computed an array Aj[0..m] where Aj[i]...
Your company is designing a part that will see a cyclically applied load, before calculating the...
Your company is designing a part that will see a cyclically applied load, before calculating the number of cycles till failure you need to determine the endurance limit. Determine the endurance limit on the given loading, geometry, and material. Given Data: Sut = 800 MPa Sy = 310 MPa Operating temperature = 120 degrees C Surface Finish: Hot-Rolled Specimen Rotating? Yes Cross-section: Solid Circle d = 20 mm Reliability = 75% Stresses Min(MPa) Max(MPa) Mean(MPa) Amp(MPa) Axial -43 82 19.5...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT