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.
Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks.
// Radio.java
public class Radio {
// attributes
private int station;
private int volume;
private boolean on;
// default constructor
public Radio() {
// setting default values
station = 1;
volume = 1;
on = false;
}
// getter methods for station and volume
public int getStation() {
return station;
}
public int getVolume() {
return volume;
}
// method to turn radio on
public void turnOn() {
on = true;
}
// method to turn radio off
public void turnOff() {
on = false;
}
// method to turn station up
public void stationUp() {
// incrementing station if not crosses the boundary
if (station < 10) {
station++;
}
}
// method to turn station down
public void stationDown() {
// decrementing station if not crosses the boundary
if (station > 1) {
station--;
}
}
// method to turn volume up
public void volumeUp() {
// incrementing volume if not crosses the boundary
if (volume < 10) {
volume++;
}
}
// method to turn volume down
public void volumeDown() {
// decrementing volume if not crosses the boundary
if (volume > 1) {
volume--;
}
}
@Override
public String toString() {
// returning proper string based on the value of 'on'
if (on) {
return "The radio station is " + station
+ " and the volume level is " + volume + ".";
} else {
return "The radio is off";
}
}
public static void main(String[] args) {
/**
* Creating a Radio object, testing all methods, displaying output
* exactly like the sample
*/
Radio radio = new Radio();
System.out.println("Turn radio on:");
radio.turnOn();
System.out.println(radio);
System.out.println("Turn volume up by 3:");
radio.volumeUp();
radio.volumeUp();
radio.volumeUp();
System.out.println(radio);
System.out.println("Move station up by 5:");
radio.stationUp();
radio.stationUp();
radio.stationUp();
radio.stationUp();
radio.stationUp();
System.out.println(radio);
System.out.println("Turn volume down by 1:");
radio.volumeDown();
System.out.println(radio);
System.out.println("Move station up by 3");
radio.stationUp();
radio.stationUp();
radio.stationUp();
System.out.println(radio);
System.out.println("Turn radio off.");
radio.turnOff();
System.out.println(radio);
System.out.println("Turn volume up by 2:");
radio.volumeUp();
radio.volumeUp();
System.out.println(radio);
System.out.println("Turn station down by 2:");
radio.stationDown();
radio.stationDown();
System.out.println(radio);
}
}
/*OUTPUT*/
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
Note: According to the question, please write source code in java only using the class method....
** 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...
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...
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...
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...
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...
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()...
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 a program (name it compareArrays) that compares the content of 2 single-dimensional arrays of the same size. The program prompts the users to enter the array size. Then prompts the user to initialize each array...
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...
1. Please write the following program in Python 3. Also, please create a UML and write the test program. Please show all outputs. (The Fan class) 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. A private bool data field named on that specifies...