检测当前电视频道的Java程序

检测当前电视频道的Java程序,java,boolean,Java,Boolean,我正在做一个项目,这将有助于确定当前的电视频道。干管的输出必须为: 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(Stri

我正在做一个项目,这将有助于确定当前的电视频道。干管的输出必须为:

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;
}   
publicstaticvoidmain(字符串[]args){
int通道[]={5,9,12,19,64};
NotVeryGoodTv tv=新的NotVeryGoodTv(频道);
打开电视();
System.out.println(“电视已经创建并调谐到频道”+TV.getCurrentChannel());
tv.channelUp();
System.out.println(“电视现在设置为频道”+TV.getCurrentChannel());
电视频道下载();
System.out.println(“电视现在设置为频道”+TV.getCurrentChannel());
对于(int i=0;i<7;i++){
tv.channelUp();
}
System.out.println(“电视现在设置为频道”+TV.getCurrentChannel());
}
专用int[]通道;//可用频道的列表
专用int currentChannel;//索引到当前选定频道的频道数组中
上的私有布尔值;//不管电视是否打开
/**
*构造器。
*在此处创建电视时,电视将关闭。
*@param channels可调谐电视的可用频道列表
*/
公共NotVeryGoodTv(国际[]频道){
开=真;
电流通道=5;
}
/**
*获取电视当前调谐到的频道
*@返回电视当前调谐的频道
*/
public int getCurrentChannel(){
//完成这个
返回-99;
}
/**
*将电视设置为特定频道
*@param channel通道数组中的通道索引。不是频道号码。
*/
公共无效setCurrentChannel(int currentChannel){
//完成这个
}
/**
*将电视调到下一个可用频道。
*如果电视未打开,此方法将不起任何作用。
*如果电视已调到最高频道,则调到最低频道。
*/
公共图书馆{
//完成这个
}
/**
*将电视调到上一频道
*如果电视未打开,此方法将不起任何作用。
*如果电视已调到最低频道,则转到最高频道。
*/
公共频道关闭(){
//完成这个
}
/**
*打开电视
*/
公共无效开关(){
//完成这个
}
/**
*关掉电视
*关闭时,您无法更改频道或检索当前频道。
*/
公共空间关闭(){
}
/**
*检查电视的开/关状态
*@return true表示电视当前已打开
*/
公共布尔值(){
布尔状态=假;
if(isOn())
返回true;
返回状态;
}   

我认为这可能是原因:

public int getCurrentChannel() {
    // finish this

    return -99;     
}
祝你作业顺利


(你至少应该尝试实现这一点,如果你被困在某个地方,问一个关于该部分的特定问题,我保证你会在这里得到答案。)

你的问题是什么??目前的结果如何?是的,可能是;)以及完全忽略其参数的构造函数或作为无限递归方法…@qqbenq不是赋值。我刚刚完成了一门编程1课,教授希望学生们在暑假期间不断受到挑战,所以我完成这门课不是为了一个看起来有点傻的分数,但我想完成这门课,以便我能从中学习,并在秋季成为一个更好的学生。我已经做了一些研究,但我还没有找到一种方法来获得我想要的结果。我有无限的时间在这方面工作,所以我会继续寻找初学者教程的帮助,只是想我会来这里寻求一些指导。我们都必须从某个地方开始。对不起,如果我显得无礼,你当然是对的:我们都必须从某个地方开始,我鼓励你试着自己解决这个问题。如果/当你面临一个比“如何解决这个难题”更具体的问题,这个社区肯定会给你答案。所以再说一遍:对不起,我的讽刺语气,但似乎你没有付出太多的努力,你只是把你的作业放在这里。如果您完成了编程1课程,那么您应该能够至少填写缺失代码的某些部分(并修复明显错误的部分)。我真的祝你好运。