gpt4 book ai didi

Java - 表达式的非法开始

转载 作者:行者123 更新时间:2023-12-01 13:19:44 24 4
gpt4 key购买 nike

所以我对这个错误进行了一些搜索并找到了一些结果。然而,这些似乎都不是答案。我确信问题很简单,而且我太累了,无法弄清楚,但我不知道我的错误是什么。这些方法旨在成为增加或减少音量的变异方法。

Television.java:94: error: illegal start of expression
public int increaseVolume()
^
Television.java:94: error: ';' expected
public int increaseVolume()
^
Television.java:103: error: illegal start of expression
public int decreaseVolume()
^
Television.java:103: error: ';' expected
public int decreaseVolume()
^
Television.java:106: error: reached end of file while parsing
}
^
5 errors

这是发生错误的代码末尾:

public class Television
{
private String MANUFACTURER = "None"; // This represents the manufacturer of the TV set.
private int SCREEN_SIZE = 0; // This represents the size of screen of the TV set.
private boolean powerOn; // This represents the state the TV is in (On or Off)
private int channel; // This represents the channel the TV set is on.
private int volume; // This represents the volume value of the TV set.

public static void main(String[] args)
{

}

/**
Constructor
@param brand The manufacturer brand of the TV set.
@param size The screen size of the TV set.
*/

public Television(String brand, int size)
{
MANUFACTURER = brand;
SCREEN_SIZE = size;
powerOn = false;
volume = 20;
channel = 2;
}

/**
The getVolume method gets the volume of the TV set.
@return The current volume on the TV set as an integer.
*/
public int getVolume()
{
return volume;
}

/**
The getChannel method gets the channel of the TV set.
@return The current channel on the TV set as an integer.
*/
public int getChannel()
{
return channel;
}

/**
The getScreenSize method gets the screen size of the TV set.
@return The screen size as an integer.
*/
public int getScreenSize()
{
return SCREEN_SIZE;
}

/**
The getManufacturer method gets the brand manufacturer of the TV set.
@return The manufacturer name as a string.
*/
public String getManufacturer()
{
return MANUFACTURER;
}

/**
The setChannel method is designed to set the channel for the user.
@return The channel on the TV that is set.
*/
public int setChannel(int chan)
{
return channel = chan;
}

/**
The power method is designed to take the current power state and turn it on or off based on its current state.
@return The power state after it is changed.
*/
public boolean power()
{
if (powerOn = true)
{
return powerOn = !powerOn;
}
else
{
return powerOn = false;
}

/**
The increaseVolume method is designed to increase the volume of the TV set in increments of 1.
@return The volume of the TV set as it is after being increased.
*/
public int increaseVolume()
{
return volume += 1;
}

/**
The decreaseVolume method is designed to decrease the volume of the TV set in increments of 1.
@return The volume of the TV set as it is after being decreased.
*/
public int decreaseVolume()
{
return volume -= 1;
}
}
}

我要么真的很累,要么就是个白痴。抱歉,如果这么明显。

最佳答案

您忘记关闭方法 power() 并在类末尾删除一个 }

除此之外,您还需要将此 if (powerOn = true) 更改为 if (powerOn == true)。您正在将值分配给 powerOn 而不是测试相等性

关于Java - 表达式的非法开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22144076/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com