簡體   English   中英

Java-非法開始表達

[英]Java - Illegal Start of Expression

因此我對該錯誤進行了一些搜索,並找到了一些結果。 但是,它們似乎都不是答案。 我確信問題很簡單,而且我太累了,無法解決,但是我不知道我的錯誤是什么。 所述方法是增加或減少體積的突變劑方法。

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錯誤(如果您再次庫存有此類錯誤)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM