SOLVE IN PYTHON:
Exercise #2: Design and implement class Radio to represent a radio object. The class defines the following attributes (variables) and methods:
Assume that the station and volume settings range from 1 to 10.
A private variable of type int named station to represent a station number. Set to 1.
A private variable of type int named volume to represent the volume setting. Set to 1.
A private variable of type boolean named on to represent the radio on or off. Set to false.
A non-argument constructor method to create a default radio.
Method getStation() that returns the station.
Method getVolume() that returns the volume.
Method turnOn() that turns the radio on.
Method turnOff() that turns the radio off.
Method stationUp() that increments the station by 1 only when the radio is on.
Method stationDown() that decrements the station by 1 only when the radio is on.
Method volumeUp() that increment the volume by 1 only when the radio is on.
Method volumeDown() that decrements the volume by 1 only when the radio is on.
Method toString()to printout a meaningful description of the radio as follows(if the radio is on):
The radio station is X and the volume level is Y. Where X and Y are the values of variables station and volume. If the radio is off, the message is: The radio is off.
Now design and implement a test program to create a default radio object and test all class methods on the object in random order. Print the object after each method call and use meaningful label for each method call as shown in the following sample run.
Sample run:
Turn radio on:
The radio station is 1 and the volume level is 1.
Turn volume up by 3:
The radio station is 1 and the volume level is 4.
Move station up by 5:
The radio station is 6 and the volume level is 4.
Turn volume down by 1:
The radio station is 6 and the volume level is 3.
Move station up by 3:
The radio station is 9 and the volume level is 3.
Turn radio off.
The radio is off.
Turn volume up by 2: The radio is off.
Turn station down by 2: The radio is off.
Program:
class Radio:
def __init__(self, station, volume,radio):
self.station = station
self.volume = volume
self.radio = radio
def getStation():
return self.station
def getVolume():
return self.volume
def turnOn(self):
self.radio = True
def turnOff(self):
self.radio = False
def stationUp(self,num):
self.station = self.station + num
def stationDown(self,num):
self.station = self.station - num
def volumeUp(self,num):
self.volume = self.volume + num
def volumeDown(self,num):
self.volume = self.volume - num
def toString(self):
return 'The radio station is',self.station,'and the volume level
is',self.volume,'.'
radioObj = Radio(1,1,False)
print("Turn radio on")
radioObj.turnOn()
print(radioObj.toString())
print("Turn volume up by 3:")
radioObj.volumeUp(3)
print(radioObj.toString())
print("Move station up by 5:")
radioObj.stationUp(5)
print(radioObj.toString())
print("Turn volume down by 1:")
radioObj.volumeDown(1)
print(radioObj.toString())
print("Move station up by 3:")
radioObj.stationUp(3)
print(radioObj.toString())
print("Turn radio off.")
radioObj.turnOff()
print("The radio is off")
print("Turn volume up by 2: ")
if(radioObj.radio==False):
print("The radio is off.")
else:
radioObj.volumeUp(2)
print(radioObj.toString())
print("Turn station down by 2: ")
if(radioObj.radio==False):
print("The radio is off.")
else:
radioObj.stationDown(2)
print(radioObj.toString())
Output:




SOLVE IN PYTHON: Exercise #2: Design and implement class Radio to represent a radio object. The c...
PYTHON Exercise #2: Design and implement class Radio to represent a radio object. The class defines the following attributes (variables) and methods: Assume that the station and volume settings range from 1 to 10. 1. A private variable of type int named station to represent a station number. Set to 1. 2. A private variable of type int named volume to represent the volume setting. Set to 1. 3. A private variable of type boolean named on to represent the...
** IN JAVA **: Design and implement class Radio to represent a radio object. The class defines the following attributes (variables) and methods:Assume that the station and volume settings range from 1 to 10.A private variable of type int named station to represent a station number. Set toA private variable of type int named volume to represent the volume setting. Set to 1.A private variable of type boolean named on to represent the radio on or off. Set to false.A...
using visual studios C# implementing using system; be sure I can copy and paste. Exercise #2: Design and implement class Radio to represent a radio object. The class defines the following attributes (variables) and methods: Assume that the station and volume settings range from 1 to 10. 1. A private variable of type int named station to represent a station number. Set to 1. 2. A private variable of type int named volume to represent the volume setting. Set to...
Note: According to the question, please write source
code in java only using the class method. Sample Run (output)
should be the same as displayed in the question below. Make sure
the source code is working properly and no errors.
Exercise #2: Design and implement class Radio to represent a radio object. The class defines the following attributes (variables) and methods Assume that the station and volume settings range from 1 to 10 1. A private variable of type int...
SOLVE IN PYTHON: Exercise #1: Design and implement class Circle to represent a circle object. The class defines the following attributes (variables) and methods: A private variable of type double named radius to represent the radius. Set to 1. Constructor Methods: Python : An overloaded constructor method to create a default circle. C# & Java: Default Constructor with no arguments. C# & Java: Constructor method that creates a circle with user-specified radius. Method getRadius() that returns the radius. Method setRadius()...
Help please
1) Define a Java class for defining the activity of a TV set. The class contains A private int data field named channel that specifies what channel is currently set for the tuner (channels range from 1 to 120, default is 1) a. b. A private int data field named volumeLevel that specifies the volume level of the TV (range is 1 to 7; default is 1) A private boolean data field named on that determines whether the...
Design and implement class Circle to represent a circle object. The class defines the following attributes (variables) and methods: 1. A private variable of type double named radius to represent the radius. Set to 1. 2. Constructor Methods: • Python : An overloaded constructor method to create a default circle. • C# & Java: Default Constructor with no arguments. • C# & Java: Constructor method that creates a circle with user-specified radius. 3. Method getRadius() that returns the radius. 4. ...
PLEASE DO BOTH OF THESE IN PYTHON 1) Exercise #1: Design and implement class Rectangle to represent a rectangle object. The class defines the following attributes (variables) and methods: Two Class variables of type double named height and width to represent the height and width of the rectangle. Set their default values to 1.0 in the default constructor. A non-argument constructor method to create a default rectangle. Another constructor method to create a rectangle with user-specified height and width. Python...
Lab # 8 The Fan class (Chapter 9:Programming Exercise 9.8) CSCI 1302 Design a class named Fan to represent a fan. The class contains: ■ Three constants named SLOW, MEDIUM, and FAST with the values 1, 2, and 3 to denote the fan speed. ■ A private int data field named speed that specifies the speed of the fan (the default is SLOW). ■ A private boolean data field named on that specifies whether the fan is on (the...
NEEDS TO BE IN PYTHON: (The Point class) Design a class named Point to represent a point with x- and y-coordinates. The class contains: - Two private data fields x and y that represent the coordinates with get methods. - A constructor that constructs a point with specified coordinates, with default point (0, 0). - A method named distance that returns the distance from this point to another point of the Point type. - A method named isNearBy(p1) that returns...