【问题标题】:Java Program to detect current TV Channel [closed]检测当前电视频道的 Java 程序 [关闭]
【发布时间】:2014-04-24 20:11:14
【问题描述】:

我正在开展一个有助于确定当前电视频道的项目。 main 的输出必须是:

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;
}   

【问题讨论】:

  • 你的问题是什么?和目前的结果?

标签: java boolean


【解决方案1】:

我认为这可能是原因:

public int getCurrentChannel() {
    // finish this

    return -99;     
}

祝你作业顺利。

(您至少应该尝试来实现这一点,如果您在某个地方遇到问题,请询问有关该部分的具体问题,我保证您在这里得到答案就这样。)

【讨论】:

  • 是的,也许它可能是 ;) 以及完全忽略其参数的构造函数或作为无限递归方法...
  • @qqbenq 不是作业。我刚刚完成了编程 1 课,教授希望在整个暑假期间让学生们保持挑战,所以我没有完成这个看起来有点傻的成绩,但我想完成它,以便我可以从中学习并成为秋季更好的学生。我已经做了一些研究,但我还没有找到一种方法来获得我正在寻找的结果。我有无限的时间来做这件事,所以我会继续寻找初学者教程来寻求帮助,只是想我会来这里寻求一些指导。我们都必须从某个地方开始。
  • 对不起,如果我看起来冒犯了,你当然是对的:我们都必须从某个地方开始,我鼓励你尝试自己解决问题。如果/当你遇到一个问题——比“如何解决这个挑战”更具体一点——这个社区一定会给你答案。再说一遍:对不起我的讽刺语气,但你似乎没有付出太多努力,你只是把你的任务放在这里。如果您完成了 Programming 1 课程,那么您应该能够至少填写缺失代码的某些部分(并且还可以修复明显错误的部分)。我真的祝你好运。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-09
  • 2019-03-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多