Question

In: Computer Science

Write a class Volume that stores the volume for a stereo that has a value between...

  1. Write 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:
    1. 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.
    2. This applies to the following methods below: __init__, set, up, down

You must write the following methods:

  1. __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.)
  2. __repr__ - converts Volume to a str for display, see runs below.
  3. set – sets the volume to the specified argument (Subject to 0 <= vol <=11 constraint above.)
  4. get – returns the numeric value of the Volume
  5. up – given a numeric amount, increases the Volume by that amount. (Subject to 0 <= vol <=11 constraint above.)
  6. down – given a numeric amount, decreases the Volume by that amount. (Subject to 0 <= vol <=11 constraint above.)
  7. __eq__ - implements the operator ==.   Returns True if the two Volumes have the same value and False otherwise.

use python 3.7

Solutions

Expert Solution

The question is missing the sample outputs, nevertheless the class has been fully implemented.

==============================================================================

class Volume():

    def __init__(self, vol=0):
        self.volume = vol
        if self.volume > 11:
            self.volume == 11
        if self.volume < 0:
            self.volume = 0

    def __repr__(self):
        return 'Stereo Volume: {}'.format(self.volume)

    def set(self, vol):
        self.volume = vol
        if self.volume > 11:
            self.volume == 11
        if self.volume < 0:
            self.volume = 0

    def get(self):
        return self.volume

    def up(self):
        self.volume += 1
        if self.volume > 11:
            self.volume == 11

    def down(self):
        self.volume -= 1
        if self.volume < 0:
            self.volume = 0

    def __eq__(self, other):
        if isinstance(other, Volume):
            return self.volume == other.volume
        else:
            return False


Related Solutions

Write a class DataSet that stores a number of values of type double in an array...
Write a class DataSet that stores a number of values of type double in an array list. Provide methods to insert a value to the array list and to compute the sum, average, and maximum value. Please put a note on what you did is for what. So I can understand this question better. Code provided: import java.util.*; public class DataSet {    private ArrayList<Double> data; /** Constructs an empty data set. @param maximumNumberOfValues the maximum this data set can...
The following information is available for Redwood Corporation for a sales volume of 500 stereo speakers...
The following information is available for Redwood Corporation for a sales volume of 500 stereo speakers for the past month: Total Per Unit Sales $112,500 $225 Less: Variable expenses 40,000 80 Contribution margin $ 72,500 $145 Less: Fixed expenses $ 17,500 Net operating income $ 55,000 If sales increase by $51,750, net income will increase by what amount? Select one: A. $33,350 B. $30,000 C. $20,000 D. $22,000
The language is java Write a class called Tablet that stores information about a tablet's age,...
The language is java Write a class called Tablet that stores information about a tablet's age, capacity (in GB), and current usage (in GB). You should not need to store any more information Write actuators and mutators for all instance data Write a toString method When you print a tablet, the info should be presented as such: This tablet is X years old with a capacity of Y gb and has Z gb used. There is A gb free on...
Write a C++ program which prompts the user to enter an integer value, stores it into...
Write a C++ program which prompts the user to enter an integer value, stores it into a variable called ‘num’, evaluates the following expressions and displays results on screen. num+5, num-3, (num+3) – 2, ((num+5)*2 / (num+3)) For performing addition and subtraction, you are allowed to use ONLY the increment and decrement operators (both prefixing and postfixing are allowed). You must remember that using increment/decrement operators changes the original value of a number. Indent your code and include comments for...
JAVA Write a Temperature class that has two instance variables: a temperature value (a floating-point number)...
JAVA Write a Temperature class that has two instance variables: a temperature value (a floating-point number) and a character for the scale, either C for Celsius or F for Fahrenheit. The class should have four constructor methods: one for each instance variable (assume zero degrees if no value is specified and Celsius if no scale is specified), one with two parameters for the two instance variables, and a no-argument constructor (set to zero degrees Celsius). Include the following: (1) two...
C++ Question Design and implement a class that stores a list of students. Each student has...
C++ Question Design and implement a class that stores a list of students. Each student has the list of courses he/she registered for the semester. You will need a container of containers to hold this list of students. Choose the optimal container for this exercise, noting that no duplicates should be permitted. Use STL classes with iterators to navigate the list. Develop a test program, which allows options to add, remove, and list students and their associated course lists. Also...
Write a paragraph about the determinants of airway resistance and the relationship between lung volume and...
Write a paragraph about the determinants of airway resistance and the relationship between lung volume and airway resistance.
Write a java program that has a class named Octagon that extends the class Circ and...
Write a java program that has a class named Octagon that extends the class Circ and implements Comparable (compare the object's area) and Cloneable interfaces. Assume that all the 8 sides of the octagon are of equal size. Your class Octagon, therefore, must represent an octagon inscribed into a circle of a given radius (inherited from Circle) and not introduce any new class variables. Provide constructors for clas Octagon with no parameters and with 1 parameter radius. Create a method...
You are to write a class StringPlay that has only a main method. This class contains...
You are to write a class StringPlay that has only a main method. This class contains all interaction with the user. The main method Uses a Scanner to accept user input Maintains a “current” String Uses a sentinel-controlled loop to accept multiple user commands, or exit The program displays a message asking the user to enter one of the following commands a – enter a new value for current b – padLeft asks the user for the number of characters...
Madison Square Stores has a $20 million bond issue outstanding that currently has a market value...
Madison Square Stores has a $20 million bond issue outstanding that currently has a market value of $19.4 million. The bonds mature in 6.5 years and pay semiannual interest payments of $35 each. What is the firm's pretax cost of debt? 7.74 percent 7.80 percent 7.59 percent 7.08 percent 8.21 percent
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT