Question
language: scala
please explain every steps thanks
• Simulate a TV without using control flow (ie. Use the state pattern) • In a package named oop.tv, create a Class named TV w
0 0
Add a comment Improve this question Transcribed image text
Answer #1
public class TV {

    public static void main(String[] args) {
        //create television object
        Television tv = new Television ();

        //invoke call methods on the object tv
        tv.changeChannel (1);
        tv.changeVolume (8);
        tv.printStatus ();

        System.out.println("I will change the the volume one time and the channel 5 times");
        tv.changeChannel(2);    tv.changeVolume(6);     tv.printStatus();
        tv.changeChannel(3);        tv.printStatus();
        tv.changeChannel(4);        tv.printStatus();
        tv.changeChannel(8);        tv.printStatus();
        tv.changeChannel(5);        tv.printStatus();

        }

}

//this is the blueprint
class TV {

    boolean power = true; //create a method for tv powerOnOff 
    int channel = 0;
    int volume = 0;


    void changeChannel (int newValue){//method to change the channel 
            channel = newValue; 
    }

    void changeVolume (int newValue){ //method to change the volume 
                volume = newValue;
    }

    void printStatus(){ //printing the status of the Television, channel and volume                 
        System.out.println("Channel: " + channel + " Volume: " + volume);
    }
}
Add a comment
Know the answer?
Add Answer to:
language: scala please explain every steps thanks • Simulate a TV without using control flow (ie....
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
  • 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...

  • Java Painter Class This is the class that will contain main. Main will create a new...

    Java Painter Class This is the class that will contain main. Main will create a new Painter object - and this is the only thing it will do. Most of the work is done in Painter’s constructor. The Painter class should extend JFrame in its constructor.  Recall that you will want to set its size and the default close operation. You will also want to create an overall holder JPanel to add the various components to. It is this JPanel that...

  • Solve it for java Question Remember: You will need to read this assignment many times to...

    Solve it for java Question Remember: You will need to read this assignment many times to understand all the details of the you need to write. program Goal: The purp0se of this assignment is to write a Java program that models an elevator, where the elevator itself is a stack of people on the elevator and people wait in queues on each floor to get on the elevator. Scenario: A hospital in a block of old buildings has a nearly-antique...

  • could you please help me with this problem, also I need a little text so I...

    could you please help me with this problem, also I need a little text so I can understand how you solved the problem? import java.io.File; import java.util.Scanner; /** * This program lists the files in a directory specified by * the user. The user is asked to type in a directory name. * If the name entered by the user is not a directory, a * message is printed and the program ends. */ public class DirectoryList { public static...

  • Hi there! I need to compare two essay into 1 essay, and make it interesting and...

    Hi there! I need to compare two essay into 1 essay, and make it interesting and choose couple topics which im going to talk about in my essay FIRST ESSAY “Teaching New Worlds/New Words” bell hooks Like desire, language disrupts, refuses to be contained within boundaries. It speaks itself against our will, in words and thoughts that intrude, even violate the most private spaces of mind and body. It was in my first year of college that I read Adrienne...

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