Question: Please help with fixing my coding errors. please let me know what line to change or add. public class TV { public static final double
Please help with fixing my coding errors. please let me know what line to change or add.
public class TV {
public static final double VOLUME_INCREMENT = 0.07; private int channel; private double volume; private int startChannel; private int endChannel; public TV(int givenStart, int givenNumChannels) { startChannel = givenStart; endChannel = givenStart + givenNumChannels -1; volume = 0.5; channel = startChannel; } public void channelDown() { channel--; if (channel < startChannel) channel = endChannel; } public void channelUp() { if (channel < endChannel) channel = startChannel; channel++; }
public void goToPreviousChannel() { channel = startChannel; } public String display() { int volPercentage = (int) (volume * 100); return "Channel" + channel + " Volume " + volPercentage + "%"; } public int getChannel() { return channel; } public double getVolume() { return volume; } public void resetStart(int givenStart) { endChannel = givenStart + (endChannel -startChannel); startChannel = givenStart; if (channel < startChannel) { channel = startChannel; } } public void resetNumChannels(int givenNumChannels) { endChannel =startChannel + givenNumChannels -1; } public void setChannel(int channelNumber) { if (channelNumber > endChannel) { channel = startChannel; } else if (channelNumber < startChannel) { channel = channelNumber; }else { channel =channelNumber; }} public void volumeDown() { volume -= VOLUME_INCREMENT; if (volume <=0) volume=0.0; } public void volumeUp() { volume += VOLUME_INCREMENT; if (volume >=1) volume=1.00; }} below are the Errors I'm getting.
PROBLEM: Message: For new TV(2, 100), after channelUp() 5 times and channelDown() twice, getChannel should return 5 expected:<5> but was:<101>
PROBLEM: Message: For new TV(-10, 5), after channelUp() 12 times, getChannel should return -8 expected:<-8> but was:<-9>
PROBLEM: Message: For new TV(4, 5), after channelUp() 12 times, getChannel should return 6 expected:<6> but was:<5>
PROBLEM: Message: For new TV(2, 100), after setChannel(500), getChannel should return 101 expected:<101> but was:<2>
PROBLEM: Message: For new TV(2, 100), after channelUp() and setChannel(-42), getChannel should return 2 expected:<2> but was:<-42>
PROBLEM: Message: For new TV(2, 100), after setChannel(42), channelDown(), and goToPreviousChannel(), getChannel should return 42 expected:<42> but was:<2>
PROBLEM: Message: For new TV(2, 100), after channelUp(), setChannel(42), and goToPreviousChannel(), getChannel should return 3 expected:<3> but was:<2>
PROBLEM: Message: For new TV(2, 100), after setChannel(17), setChannel(42), and goToPreviousChannel(), getChannel should return 17 expected:<17> but was:<2>
PROBLEM: Message: For new TV(4, 5), after channelDown() 12 times and goToPreviousChannel(), getChannel should return 8 expected:<8> but was:<4>
PROBLEM: Message: For new TV(2, 100), after setChannel(42), setChannel(17) and goToPreviousChannel() 5 times, getChannel should return 42 expected:<42> but was:<2>
PROBLEM: Message: For new TV(2, 100), display() should return the string "Channel 2 Volume 50%" expected:
PROBLEM: Message: For new TV(2, 100), after setChannel(42) and volumeUp() twice, display() should return the string "Channel 42 Volume 64%" expected:
PROBLEM: Message: For a new TV(2, 10), after setChannel(9) and resetStart(-4), channel should be 5 expected:<5> but was:<9>
PROBLEM: Message: For new TV(2, 100), after volumeUp() 10 times and volumeDown() 4 times, display() should return the string "Channel 2 Volume 72%" expected:
PROBLEM: Message: For a new TV(0, 6), after resetNumChannels(4) and channelUp() 7 times, channel should be 3 expected:<3> but was:<1>
PROBLEM: Message: For a new TV(2, 10), after setChannel(9) and resetNumChannels(5), channel should be 6 expected:<6> but was:<9>
PROBLEM: Message: For a new TV(2, 10), after setChannel(9), setChannel(2), resetNumChannels(5), and goToPreviousChannel(), channel should be 6 expected:<6> but was:<2>
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
