2016-03-04 336 views
1

编译此代码时出现同样的错误。我想知道如何成功添加出租天数和出租率。请帮忙。为什么我继续收到此错误“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; 
    } 

} 

回答

0

变化

int RentalProfit; 

    RentalDays + RentalRate = RentalProfit; 

return RentalDays + RentalRate; 
+0

谢谢sanky耆那教 – MajorJavaUser

+0

这样做是为你工作。请接受我的回答 –

1

只写代码来添加。

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

RentalDays + RentalRate = RentalProfit;是无效的,因为=运营商的左侧大小应分配给,不是相加结果的变量。
您的意思是?

+0

谢谢MikeCat – MajorJavaUser

相关问题