我正在开展一个有助于确定当前电视频道的项目。主要的输出必须是:
The TV has been created and is tuned to channel 5
The TV is now set to channel 9
The TV is now set to channel 5
The TV is now set to channel 12
这是我到目前为止:请帮助我实现正确的输出。目前我的输出为-99。谢谢
public static void main(String[] args) {
int channels[] = {5,9,12,19,64};
NotVeryGoodTv tv = new NotVeryGoodTv(channels);
tv.turnOn();
System.out.println("The TV has been created and is tuned to channel " + tv.getCurrentChannel());
tv.channelUp();
System.out.println("The TV is now set to channel " + tv.getCurrentChannel());
tv.channelDown();
System.out.println("The TV is now set to channel " + tv.getCurrentChannel());
for (int i = 0; i < 7; i++) {
tv.channelUp();
}
System.out.println("The TV is now set to channel " + tv.getCurrentChannel());
}
private int [] channels; // The list of available channels
private int currentChannel; // The index into the channels array of the currently selected channel
private boolean on; // Whether or not the TV is turned on
/**
* Constructor.
* The TV is turned off when it is created here.
* @param channels The list of available channels that the TV can be tuned to
*/
public NotVeryGoodTv(int[] channels) {
on = true;
currentChannel=5;
}
/**
* Get the channel to which the TV is currently tuned
* @return The channel to which the TV is currently tuned
*/
public int getCurrentChannel() {
// finish this
return -99;
}
/**
* Set the TV to a specific channel
* @param channel The channel index in the array of channels. NOT the channel number.
*/
public void setCurrentChannel(int currentChannel) {
// finish this
}
/**
* Tune the TV to the next available channel.
* If the TV is not turned on, this method will do nothing.
* If the TV is already tuned to the highest channel, wrap around to the lowest channel.
*/
public void channelUp(){
// finish this
}
/**
* Tune the TV to the previous channel
* If the TV is not turned on, this method will do nothing.
* If the TV is already tuned to the lowest channel, wrap around to the highest channel.
*/
public void channelDown(){
// finish this
}
/**
* Turn the TV on
*/
public void turnOn() {
// finish this
}
/**
* Turn the TV off
* When it's off, you can't change channels or retrieve the current channel.
*/
public void turnOff() {
}
/**
* Check the on/off status of the TV
* @return true is the TV is currently turned on
*/
public boolean isOn() {
boolean status = false;
if (isOn())
return true;
return status;
}
答案 0 :(得分:2)
我认为这可能是原因:
public int getCurrentChannel() {
// finish this
return -99;
}
祝你的作业好运。
(你应该至少尝试来实现这一点,如果你遇到某个地方问一个关于该部分的具体问题,我保证你将在这里获得答案在SO。)