Question

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

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

Hi, PFA for the sample run

Please find below the code for the implementation of the same:

using System;

public class Program
{
   public static void Main()
   {
       Radio radioObj = new Radio();
       radioObj.toString();
       radioObj.volumeDown();
       radioObj.turnOn();
       radioObj.toString();
       radioObj.stationUp();
       radioObj.toString();
       radioObj.volumeUp();
       radioObj.toString();
       radioObj.volumeDown();
       radioObj.toString();
       radioObj.turnOff();          
   }
}
public class Radio
{
   private int station;
   private int volume;
   private bool isRadioTurnedOn;
  
   public Radio()
   {
       this.station = 1;
       this.volume=1;
       this.isRadioTurnedOn=false;
   }
   public int getStation()
   {
       return this.station;
   }
   public int getVolume()
   {
       return this.volume;
   }
   public void turnOn(){
       this.isRadioTurnedOn = true;
   }
   public void turnOff(){
       this.isRadioTurnedOn = false;
   }
   public void stationUp(){
       if(this.isRadioTurnedOn && this.station<10){
           this.station = this.station+1;
       }
       else{
           Console.WriteLine("Unable to Up the station as the radio is "+ (this.isRadioTurnedOn?"On":"Off") + " and station in "+this.station);
       }
   }
   public void volumeUp(){
       if(this.isRadioTurnedOn && this.volume<10){
           this.volume = this.volume+1;
       }
       else{
           Console.WriteLine("Unable to Up the Volume as the radio is "+ (this.isRadioTurnedOn?"On":"Off") + " and volume in "+this.volume);
       }
   }
   public void stationDown(){
       if(this.isRadioTurnedOn && this.station>1){
           this.station = this.station-1;
       }
       else{
           Console.WriteLine("Unable to Down the station as the radio is "+ (this.isRadioTurnedOn?"On":"Off") + " and station in "+this.station);
       }
   }
   public void volumeDown(){
       if(this.isRadioTurnedOn && this.volume>1){
           this.volume = this.volume-1;
       }
       else{
           Console.WriteLine("Unable to Down the Volume as the radio is "+ (this.isRadioTurnedOn?"On":"Off") + " and volume in "+this.volume);
       }
   }
   public void toString()
   {
       if(this.isRadioTurnedOn)
       {
           Console.WriteLine("The radio station is {0} and the volume level is {1}.", this.getStation(), this.getVolume());
       }
       else
       {
           Console.WriteLine("Please turn on the radio!!!");
       }
   }

}

Kindly revert me in case of any queries. Thank you.

Add a comment
Know the answer?
Add Answer to:
using visual studios C# implementing using system; be sure I can copy and paste. Exercise #2:...
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
  • 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...

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

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

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

  • PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE IN VISUAL STUDIO Exercise #1:...

    PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE IN VISUAL STUDIO Exercise #1: Design and implement class Rectangle to represent a rectangle object. The class defines the following attributes (variables) and methods: 1. 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. 2. A non-argument constructor method to create a default rectangle. 3. Another constructor method to...

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

  • 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()...

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

  • Using C# Language Develop a Visual C# .NET application that performs a colour control operation. The...

    Using C# Language Develop a Visual C# .NET application that performs a colour control operation. The main form contains a reset button and sets the form's background colour according to the colour values indicated by the colour control objects. Each colour control object is controlled by a corresponding colour control form which provides a progress bar to show the value (in the range 0 to 255) of the corresponding colour control object. The user can click the increase (+) or...

  • PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE IN VISUAL STUDIO Program 2:...

    PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE IN VISUAL STUDIO Program 2: Design (pseudocode) and implement (source code) a class called Counter. It should have one private instance variable representing the value of the counter. It should have two instance methods: increment() which adds on to the counter value and getValue() which returns the current value. After creating the Counter class, create a program that simulates tossing a coin 100 times using two Counter objects (Head...

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