Question

** IN JAVA **: Design and implement class Radio to represent a radio object. The class defines th...

** 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.

  1. A private variable of type int named station to represent a station number. Set to

  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 radio on or off. Set to false.

  4. A non-argument constructor method to create a default radio.

  5. Method getStation() that returns the station.

  6. Method getVolume() that returns the volume.

  7. Method turnOn() that turns the radio on.

  8. Method turnOff() that turns the radio off.

  9. Method stationUp() that increments the station by 1 only when the radio is on.

  10. Method stationDown() that decrements the station by 1 only when the radio is on.

  11. Method volumeUp() that increment the volume by 1 only when the radio is on.

  12. Method volumeDown() that decrements the volume by 1 only when the radio is on.

  13. 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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

class Radio
{
private int station;
private int volume;
private boolean on;

public Radio() // default constructor
{
station = 1;
volume = 1;
on = false;
}

//get methods
public int getStation()
{
return station;
}
public int getVolume()
{
return volume;
}
public void turnOn()
{
on = true;
}
public void turnOff()
{
on = false;
}
public void stationUp()
{
if(on == true)
station++;
}

public void stationDown()
{
if(on == true)
station--;
}
public void volumeUp()
{
if(on == true)
volume++;
}
public void volumeDown()
{
if(on == true)
volume--;
}
public String toString()
{
if(on == true)
return "The radio station is "+station+" and the volume level is "+volume;
else
return "The radio is off";
}

}

class TestRadio
{
public static void main (String[] args)
{
  Radio r1 = new Radio();
  r1.turnOn();
  System.out.println(r1);
  
  
  r1.volumeUp();
  r1.volumeUp();
  r1.volumeUp();
  System.out.println(r1);
  
  r1.stationUp();
  r1.stationUp();
  r1.stationUp();
  r1.stationUp();
  r1.stationUp();
  System.out.println(r1);
  
  r1.volumeDown();
  System.out.println(r1);
  
  r1.stationDown();
  r1.stationDown();
  r1.stationDown();
  
  r1.volumeDown();
  
  r1.stationUp();
  r1.stationUp();
  r1.stationUp();
  
  System.out.println(r1);
  r1.turnOff();
  
  System.out.println(r1);
  
  r1.volumeUp();
  r1.volumeUp();
  System.out.println(r1);
  
  r1.stationDown();
  r1.stationDown();
  System.out.println(r1);
  
  


}
}

Output:

The radio station is 1 and the volume level is 1
The radio station is 1 and the volume level is 4
The radio station is 6 and the volume level is 4
The radio station is 6 and the volume level is 3
The radio station is 6 and the volume level is 2
The radio is off
The radio is off
The radio is off

Do ask if any doubt. Please upvote.

Add a comment
Know the answer?
Add Answer to:
** IN JAVA **: Design and implement class Radio to represent a radio object. The class defines th...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PYTHON Exercise #2: Design and implement class Radio to represent a radio object. The class defines...

    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...

  • SOLVE IN PYTHON: Exercise #2: Design and implement class Radio to represent a radio object. The c...

    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...

  • using visual studios C# implementing using system; be sure I can copy and paste. Exercise #2:...

    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....

    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...

  • Help please 1) Define a Java class for defining the activity of a TV set. The...

    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...

    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.     ...

  • SOLVE IN PYTHON: Exercise #1: Design and implement class Circle to represent a circle object. 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()...

  • C# Language The ColourControl Class The class should be public. The class defines a read-only or...

    C# Language The ColourControl Class The class should be public. The class defines a read-only or private set public property named Value of type int. The class defines a public event named ValueChanged whose delegate type is void with two parameters, object sender and EventArgs e. The public constructor for the class is a default constructor (i.e., takes no parameters). The constructor sets the Value property to 128. The class defines a public void method named IncreaseValue. The method increases...

  • Java - Object Oriented Programming Declare a class named Customer that has two private fields? Write...

    Java - Object Oriented Programming Declare a class named Customer that has two private fields? Write a set method to make sure that if age > 125 years or less than 0 then it is set to 0 (default value) What does it indicate when declaring a class's instance variables with private access modifier? What is the role of a constructor? The data part of by an object's instance variables is known as? Do all methods have to always return...

  • THE FOLLOWING PROGRAM IS NEEDED IN JAVA LANGUAGE Design a class torepresent account, include the following...

    THE FOLLOWING PROGRAM IS NEEDED IN JAVA LANGUAGE Design a class torepresent account, include the following members: -Data Members a)Name of depositor-Stringb)Account Number –intc)Type of account –Boolean d)Balance amount -doublee)AnnualInterestrate -double Methods: -(a)To assign initial values (use constructor)(b)To deposit an amount.(c)TO withdraw amount with the restriction the minimum balance is 50 rs. Ifyouwithdraw amount reduced the balance below 50 then print the error message.(d)Display the name and balance of the account.(e)Get_Monthly_intrestRate() -Return the monthly interestrate whichis nothing but Annualintrestrate/12. Annualinterestrate...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT