编译此代码时出现同样的错误。我想知道如何成功添加租赁天数和租金率。请帮助。
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 :(得分:1)
只需编写要添加的代码。
public int RentalProfit(int RentalRate, int RentalDays)
{
return RentalDays + RentalRate;
}
RentalDays + RentalRate = RentalProfit;
无效,因为=
运算符的左手大小应该是要分配的变量,而不是添加的结果。
您的意思是RentalProfit = RentalDays + RentalRate;
吗?
答案 1 :(得分:0)
更改
destroy
到
public class CustomTabLayout extends TabLayout {
public CustomTabLayout(Context context) {
super(context);
}
public CustomTabLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomTabLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
try {
if (getTabCount() == 0)
return;
Field field = TabLayout.class.getDeclaredField("mTabMinWidth");
field.setAccessible(true);
field.set(this, (int) (getMeasuredWidth() / (float) getTabCount()));
} catch (Exception e) {
e.printStackTrace();
}
}
}