
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Use Python for this question:
- Develop a class Volume that stores the volume for a stereo that has a value between 0 and 11. Usage of the class is listed below the problem descriptions. Throughout the class you must guarantee that:
- The numeric value of the Volume is set to a number between 0 and 11. Any attempt to set the value to greater than 11 will set it to 11 instead, any attempt to set a negative value will instead set it to 0.
- This applies to the following methods below: __init__, set, up, down
You must write the following methods:
- __init__ - constructor. Construct a Volume that is set to a given numeric value, or, if no number given, defaults the value to 0. (Subject to 0 <= vol <=11 constraint above.)
- __repr__ - converts Volume to a str for display, see runs below.
- set – sets the volume to the specified argument (Subject to 0 <= vol <=11 constraint above.)
- get – returns the numeric value of the Volume
- up – given a numeric amount, increases the Volume by that amount. (Subject to 0 <= vol <=11 constraint above.)
- down – given a numeric amount, decreases the Volume by that amount. (Subject to 0 <= vol <=11 constraint above.)
- __eq__ - implements the operator ==. Returns True if the two Volumes have the same value and False
Output is in the 2 attached images for this question:
Please run a doctest so the function returns the following output, which is attached in an image

Transcribed Image Text:# default arguments for init
-
-
>>> v = volume () # Volume defaults to 0
>>> v
Volume (0)
# can compare Volumes using
==
>>> # comparisons
>>> v = Volume (5)
>>> v.up (1.1)
>>> v == Volume (6.1)
True
>>> Volume (3.1)
== Volume (3.2)
False
# constructor cannot set the Volume greater
# than 11 or less than 0
>>> v = volume (20)
>>> v
Volume (11)
>>> v = Volume (-1)
>>> v
Volume (0)
>>>

Transcribed Image Text:##### Volume #####
# set and get
>>> v = volume ()
>>> v.set (5.3)
>>> v
Volume (5.3)
>>> v.get ()
5.3
>>> v.get () ==5.3 # return not print
True
>>>
init_,
_repr_, up, down
>>> v = volume (4.5) # set Volume with value
>>> v
Volume (4.5)
>>> v.up (1.4)
>>> v
Volume (5.9)
>>> v.up (6) # should max out at 11
>>> v
Volume (11)
>>> v.down (3.5)
>>> v
Volume (7.5)
>>> v.down (10) # minimum must be 0
>>> v
Volume (0)
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images

Knowledge Booster
Similar questions
- C++ language pleasearrow_forwardConvert the pseudocode into Python. 1. Pet ClassDesign a class named Pet, which should have the following fields:■ name: The name field holds the name of a pet.■ type: The type field holds the type of animal that a pet is. Example values are "Dog", "Cat", and "Bird".■ age: The age field holds the pet’s age.2. The Pet class should also have the following methods:■ setName: The setName method stores a value in the name field.■ setType: The setType method stores a value in the type field.■ setAge: The setAge method stores a value in the age field.■ getName: The getName method returns the value of the name field.■ getType: The getType method returns the value of the type field.■ getAge: The getAge method returns the value of the age field.3. Once you have designed the class, design a program that creates an object of the class and prompts the user to enter the name, type, and age of his or her pet. This data should be stored in the object. Use the…arrow_forwardJAVA CODE Class Description: Your need to create an instantiable class that represents a parcel of raw land that can be sold by a real estate company. This class should be named Land. It will contain three fields: a string named location and a width and length, measured in feet, each of which can accept numbers with decimal points. You may assume that every parcel of land is rectangular and that 'width' describes the size of the property along the road and 'length' is how far back it goes from the road. The class needs one constructor that sets the values all the fields. The class needs the following public methods: • Getters and setters for all fields. • A method called getArea that calculates and returns the area of the parcel of land in square feet. (Area is calculated as length x width.) • Standard methods: toString, equals, and hashCode where equals and hashCode define two equivalent parcels of land as each having the same length and each having the same width. • Implementation…arrow_forward
- Use java and classesarrow_forwardWrite a code in Java programming You are working in a game company that is developing a new RPG game. One of the core features of the game is the ability to create and manage different types of characters, such as warriors, mages, and archers. However, your colleague, who was previously working on the implementation of the CharacterManager class, has been laid off due to excessive absences. You have been assigned to take over the project and complete the implementation of the class based on the design specifications outlined below: Given the following main method: public static void main(String[] args) { CharacterManager manager = CharacterManager.getInstance(); manager.createCharacter(CharacterType.WARRIOR).attack(); manager.createCharacter(CharacterType.MAGE).attack(); manager.createCharacter(CharacterType.ARCHER).attack(); } Your output should be: Warrior is attacking Mage is attacking Archer is attacking Note that you should not change the method signature.arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY

Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON

Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education

Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY