繁体   English   中英

为什么我不断收到此错误“错误:意外类型”

[英]Why do I keep on getting this error “error: unexpected type”

编译此代码时出现相同的错误。 我想知道如何成功添加“出租天数”和“出租率”。 请帮忙。

 Tractor.java:83: error: unexpected type
         RentalDays + RentalRate = RentalProfit;
                    ^
 required: variable
  found value
1 error

码:

 import java.util.*;

 public class Tractor
{
   private String name;
   private int VehicleID; 
   private int RentalRate;
   private int RentalDays;


   public int setRentalRate(int RentalRate)
{
    if (RentalRate <= 0 || RentalRate > 100000) 
    {
      return -1;
    } 
    else 
    {
        return this.RentalRate;

    }
 }

public int getRentalRate()
 {
     return this.RentalRate;
 }

  public int setRentalDays(int RentalDays)
{
    if (RentalDays <= 0 || RentalDays > 365) 
    {
      return -1;
    } 
    else 
    {
        return this.RentalDays;

    }
 }

public int getRentalDays()
 {
     return this.RentalRate;
 }

  public int RentalProfit(int RentalRate, int RentalDays)
  {
     int RentalProfit;

     RentalDays + RentalRate = RentalProfit;
  }

}

只需编写代码即可添加。

public int RentalProfit(int RentalRate, int RentalDays)
{
  return RentalDays + RentalRate;
}

RentalDays + RentalRate = RentalProfit; 之所以无效,是因为=运算符的左手大小应为要分配的变量,而不是加法的结果。
您的意思是RentalProfit = RentalDays + RentalRate;

更改

int RentalProfit;

     RentalDays + RentalRate = RentalProfit;

    return RentalDays + RentalRate;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM