Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Trying to do a mute function for a TV. Didn\'t post the entire code but here are

ID: 3708550 • Letter: T

Question

Trying to do a mute function for a TV. Didn't post the entire code but here are the private instance variables, and then my mute fuctions below. Can someone tell me why my code function for muteOff isn't working. It says unexpected type for the second type of my muteOff function.

public class Tv {
//private instance variables
private String brand;
private String model;
private boolean power;
private int channel = 2;
private int volume = 4 ; //volume set to approximately 20% of the max allowed value
private boolean mute;

public void muteOn (){ //mute on
if (power && volume > 1)
mute = true;
}
  
public void muteOff (){ ////mute off
if (power && mute = true) //tried to turn mute off if mute was on
mute = false;
}

Explanation / Answer

Hi

I have fixed the issue and highlighted the code changes below.

public class Tv {
//private instance variables
private String brand;
private String model;
private boolean power;
private int channel = 2;
private int volume = 4 ; //volume set to approximately 20% of the max allowed value
private boolean mute;

public void muteOn (){ //mute on
if (power && volume > 1)
mute = true;
}
  
public void muteOff (){ ////mute off
if (power && mute == true) //tried to turn mute off if mute was on
mute = false;
}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote