public static void listRentalDetailsOverPeriod(ArrayList customerList)
{
Scanner input = new Scanner(System.in);
Customer c = null;
Vehicle v = null;
System.out.println("Enter Ic Number:");
String icNo = input.nextLine();
for(int i=0;i<customerList.size();i++)
{//start of for loop
Customer cust = (Customer) customerList.get(i);
if(cust.getIcNo().equalsIgnoreCase(icNo))
{
c = cust;
break;
}
}//end of for loop
ArrayList rentalList = c.getRentalList();
System.out.print("Enter Start Date(DD MM YYYY): ");
int dd = input.nextInt();
int mm = input.nextInt();
int yyyy = input.nextInt();
Calendar dob = new GregorianCalendar(yyyy,mm-1,dd);//creates calendar object
System.out.print("Enter End Date(DD MM YYYY): ");
int dd1 = input.nextInt();
int mm1 = input.nextInt();
int yyyy1 = input.nextInt();
Calendar dob1 = new GregorianCalendar(yyyy1,mm1-1,dd1);//creates calendar object
for(int i=0;i<rentalList.size();i++)
{//start of for loop
Rental r = (Rental) rentalList.get(i);//create rental object
if(r.getPickupDate() > dob && r.getReturnDate() < dob1)
{
System.out.println(r);
}
}//end of for loop
}
错误:
VehicleRental.java:660: error:
bad operand types for binary operator '>'
if(r.getPickupDate() > dob && r.getReturnDate() < dob1)
我在尝试编译此代码时遇到错误,我对二进制运算符的操作数越来越差。我试图在一段时间内显示客户的租赁细节。
答案 0 :(得分:1)
最有可能的是,r.getReturnDate
不返回数值(整数,双精度,长整数等)我假设它返回一个Date
/ Calendar
对象,而你无法将对象与二元运算符。这就是为什么它们被称为BINARY运算符;)
解决方案: 使用: 日历#之前(obj)或#after(对象)
if(r.getPickupDate().after(dob) && r.getReturnDate().before(dob1)){
//do stuff
}
答案 1 :(得分:0)
您无法将Object
个实例与<
或>
进行比较。您应该使用Calendar.before(Object)
和Calendar.after(Object)
代替。像,
if(r.getPickupDate().after(dob) && r.getReturnDate().before(dob1))
{
System.out.println(r);
}