Question

In: Computer Science

JAVA, this is practice to better understand java. //Please note throughout if possible looking to better...

JAVA, this is practice to better understand java.
//Please note throughout if possible looking to better understand the process.

Write the following class: TV.
Define Class TV
Write the class header

Class Variables
Class TV is to have the following instance variables:
1.channel of type int
2. volumeLevel of type int
3. isOn of type boolean

Each data member is to have an access specifier of private.

Constructor
Class TV is to have a single, no-arg constructor that initializes the instance variables to zero or false.

Get and Get Methods
Class TV has neither get( ) nor set( ) methods

Auxiliary Methods
In place of standard get/set methods, class TV will have the following public auxiliary methods:
1. a void method turnOn( ), that takes no parameters and sets isOn to true;
2. a void method turnoff( ), that takes no parameters and sets isOn to false;
3. a void method setChannel( ) that takes an integer parameter named newChannel and assigns the instance variable channel to the parameter value;
4. a void method setVolume( ) that takes an integer parameter named newVolumeLevel and assigns the instance variable volumeLevel to the parameter value;
5. a void method channelUp( ) that takes no parameters and increments the instance variable channel by one;
6. a void method channelDown( ) that takes no parameters and decrements the instance variable channel by one;
7. a void method volumeUp( ) that takes no parameters and increments the instance variable volume by one;
8. a void method volumeDown( ) that takes no parameters and decrements the instance variable volume by one.

Method Overrides
Class TV is to override the Object equals( ) method to do the following:
1. test to see if the parameter represents an object;
2. test to see if the parameter object is of the same class type as the calling object;
3. determine if the calling object and the parameter object store identical data values for the corresponding data members.

Class TV is to override the Object toString( ) method that does the following:
1. displays the following information in the format presented:
Current Channel: display channel data
Volume Level: display volumeLevel data
Power: display isOn data

Solutions

Expert Solution

TV.java

/*
* Class Name: TV
* Description: class to define a TV
* Author: Your name
*
*/
public class TV {
   //data members
   private int channel;
   private int volumeLevel;
   private boolean isOn;
  
   //constructor
   public TV() {
       channel = 0;
       volumeLevel = 0;
       isOn = false;
   }
  
   //methods to turn on and off
   public void turnOn() {
       isOn = true;
   }
  
   public void turnOff() {
       isOn = false;
   }
  
   //methods to set channel and volume
   public void setChannel(int newChannel) {
       channel = newChannel;
   }
  
   public void setVolume(int newVolumeLevel) {
       volumeLevel = newVolumeLevel;
   }
  
   //methods to turn up and down the channel and volume
   public void channelUp() {
       channel++;
   }
  
   public void channelDown() {
       channel--;
   }
  
   public void volumeUp() {
       volumeLevel++;
   }
  
   public void volumeDown() {
       volumeLevel--;
   }
  
   //overriding equals method
   @Override
   public boolean equals(Object arg0) {
       if(arg0 instanceof Object && arg0 instanceof TV && ((TV)arg0).channel == this.channel && ((TV)arg0).volumeLevel == this.volumeLevel && ((TV)arg0).isOn == this.isOn) {
           return true;
       }
       return false;
   }
  
   //overriding toString method
   @Override
   public String toString() {
       String outString = "";
       outString += "\nCurrent Channel: " + this.channel;
       outString += "\nVolume Level: " + this.volumeLevel;
       outString += "\nPower: " + this.isOn;
       return outString;
   }
}

Main.java


public class Main {

   public static void main(String[] args) {
       //initializing two TVs
       TV tv1 = new TV();
       TV tv2 = new TV();
       //printing
       System.out.println("\nTV1 : " + tv1.toString());
       System.out.println("\nTV2 : " + tv2.toString());
       //calling the method
       tv1.turnOn();
       tv1.setChannel(5);
       tv1.channelUp();
       tv1.setVolume(50);
       tv1.volumeDown();
       //printing data
       System.out.println("\nTV1 : " + tv1.toString());
       tv2.turnOn();
       tv2.setChannel(5);
       tv2.channelUp();
       tv2.setVolume(50);
       tv2.volumeDown();
       System.out.println("\nTV2 : " + tv2.toString());
       //checking if two TVs are equal
       System.out.println("\nTV1 equals TV2?: " + tv1.equals(tv2));
       //turning off the 2nd TV
       tv2.turnOff();
       System.out.println("\nTV2 : " + tv2.toString());
       //checking if two TVs are equal now
       System.out.println("\nTV1 equals TV2?: " + tv1.equals(tv2));

   }

}

Sample Output:


TV1 :
Current Channel: 0
Volume Level: 0
Power: false

TV2 :
Current Channel: 0
Volume Level: 0
Power: false

TV1 :
Current Channel: 6
Volume Level: 49
Power: true

TV2 :
Current Channel: 6
Volume Level: 49
Power: true

TV1 equals TV2?: true

TV2 :
Current Channel: 6
Volume Level: 49
Power: false

TV1 equals TV2?: false


Related Solutions

JAVA, this is practice to better understand java. //Please note throughout if possible looking to better...
JAVA, this is practice to better understand java. //Please note throughout if possible looking to better understand the process. Write the following class: Person. Define Class Person Write the class header Class Variables Class Person is to have the following data members: firstName of type String, lastName of type String representing a person’s first and last names and ssn of type int representing a social security number. Each data member has an access specifier of type private. Constructors Class Person...
JAVA, trying to better learn and use JAVA //Please note throughout if possible looking to better...
JAVA, trying to better learn and use JAVA //Please note throughout if possible looking to better understand the process. Write the following class: Box Define Class Box Write the class header Class Variables Class Box is to have the following private data members: height of type double width of type double length of type double Constructors Class Box is to have two constructors with the following specifications: a no-arg constructor that initializes each double data member to zero a constructor...
To better understand if it was possible to consider opening more locations, Robert wanted to know...
To better understand if it was possible to consider opening more locations, Robert wanted to know how much equity he had in his business and used the following totals to help in his calculations: Beginning capital = $35,000 Drawings = $4,000 Net income = $18,000 Investment by owner = $9,000 __________ was the ending owner’s equity that Robert calculated.
Note: I need a step by step answer to the following problem to better understand how...
Note: I need a step by step answer to the following problem to better understand how this works. Hot Coffee Manufacturing produces and sells oak tables. The budgeted   manufacturing costs per table are as follows: Direct costs                 Oak top                48 square feet at $10 per sq. ft.                 Table legs                 4 legs at $5 per leg Direct labor is 3 hours and 24 minutes per table at $15 per hour. The variable overhead rate is $6 per...
on C++ language please and if you can also put note on it to better undertand...
on C++ language please and if you can also put note on it to better undertand it. Write a program that reads data from a data file, the value of which is provided at the end of the problem. Your program is to incorporate the following requirements: Data to the program is input from a file of an unspecified length; that is, the program does not know in advance how many numbers are in the file. Save the output of...
This is an Intro to java question. Please provide code and pseudocode for better understanding. Problem...
This is an Intro to java question. Please provide code and pseudocode for better understanding. Problem 4: Player Move Overworld (10 points) (Game Development) You're the lead programmer for an indie game studio making a retro-style game called Zeldar. You've been tasked to implement the player movement. The game is top-down, with the overworld modeled as a 2d grid. The player's location is tracked by x,y values correlating to its row and column positions within that grid. Given the current...
Please read the article “A better way to understand internal rate of return” of McKinsey, November...
Please read the article “A better way to understand internal rate of return” of McKinsey, November 2015. As we have already learnt how to calculate IRR and main assumption about this project evaluation criteria do you see the way we should approach IRR suggested by McKinsey a useful recommendation? What are additional criteria on top of those we learnt in the class we can use?
Please show full work if possible, would like to be able to understand the problem and...
Please show full work if possible, would like to be able to understand the problem and solution. Leo company is considering a new venture in office equipment. It expects the cost of acquisition of land and building to be $100,000. Leo company expects cash flows to be $40,000 the first year and $45,000 for the next 4 years. It will discontinue the furniture operation upon the completions of the 5th year. Assume no salvage value. The company’s WACC is 10%....
Please show full work if possible, would like to be able to understand the problem and...
Please show full work if possible, would like to be able to understand the problem and solution. Lion Inc. recently hire you as a consultant to estimate the company’s WACC. You have obtained the following information. (1) The firm’s noncallable bonds mature in 20 years, have an 8% annual coupon, a par value of $1,000, and a market price of $1,050. (2) The company’s tax rate is 40%. (3) The risk-free rate is 4.50% and the market risk premium is...
The choice of ≤ or ≥ is not trivial. To better understand this, consider the following...
The choice of ≤ or ≥ is not trivial. To better understand this, consider the following statement: Tom is sent to the store with $20 to buy soda and chips. Each bottle of soda costs $3 and each bag of chips costs $2. Let s = soda and c = chips. What would it mean if we wrote: 3s+2c≥20? Tom can spend up to $20. Tom has to spend at least $20. Translate the following statements into inequalities. Be sure...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT