2016-03-04 334 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

相關問題