Java-表达式的非法开始
因此,我对这个错误进行了一些搜索,并找到了一些结果。然而,它们似乎都不是答案。我确信问题很简单,我只是太累了,想不出来,但我不知道我的错误是什么。这些方法是用来增加或减少体积的变异方法Java-表达式的非法开始,java,Java,因此,我对这个错误进行了一些搜索,并找到了一些结果。然而,它们似乎都不是答案。我确信问题很简单,我只是太累了,想不出来,但我不知道我的错误是什么。这些方法是用来增加或减少体积的变异方法 Television.java:94: error: illegal start of expression public int increaseVolume() ^ Television.java:94: error: ';' expected public int increaseVolume()
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
而不是测试相等性您在public boolean power()
方法中缺少一个右括号
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;
}
}////here is missing breces
/**
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;
}
}
}
您在这里错过了一个
}
:
public boolean power()
{
if (powerOn = true)
{
return powerOn = !powerOn;
}
else
{
return powerOn = false;
}
//
//Here is } missing
//
/**
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;
}
无论如何,如果您在编译时出错,我建议您使用IDE检查sintax错误,如果您再次存储此类错误是否从某个地方复制源代码?它不是在calss之外,就是在另一个方法内部。这只是猜测-括号不匹配与上面的代码不匹配
public int increaseVolume().
您可能错过了一个
或}。
如果找不到问题,请发布完整的代码。发布完整的代码。。在我看来,你在课程结束时多给了一个大括号