Java正在访问Arraylist并将其与String参数进行比较?

问题描述 投票:1回答:1

我正在研究停车罚单模拟器,我试图编写一种使用汽车牌照作为参数的方法,该方法搜索官员名单的集合并返回发给特定汽车的罚单数量。我有这些课程

public class ParkedCar {


private String ownerName;
private String carMake;
private String licensePlateNumber;
private int modelYear;
private int numberOfMinutesParked;

public class ParkingTicket {
    private String officerName;
    private String officerBadgeNumber;
    private String ticketNumber;
    private String carLicensePlateNumber;
    private double fineAmountInCAD;

public class PoliceOfficer
{ 

    private String officerName;
    private String officerBadgeNumber;
    private ArrayList<ParkingTicket> ticketList;

import java.util.ArrayList;
import java.util.Iterator;
public class PoliceDepartment
{ 

    private String address;
    private ArrayList<PoliceOfficer> officerList;

我的方法目前看起来像这样

public int totalParkingTicketCountOfACar

int totalCount = 0;
    int totalCount = 0;
        ArrayList<PoliceOfficer> carTickets = new ArrayList<PoliceOfficer>();

    Iterator<PoliceOfficer> it = carTickets.iterator();

     while(it.hasNext()){

            PoliceOfficer carticket = it.next();


         if(officerList.equalsIgnoreCase(licensePlateNumber)){
             totalCount++;
            }
        }

          return totalCount;

我不确定如何将所有人员都列入清单并将其与该车牌进行比较,以获取发给特定​​汽车的车票数量?任何帮助深表感谢 ! :)

java oop arraylist
1个回答
2
投票
每个PoliceDepartment都有PoliceOfficer的列表。每个PoliceOfficer都有一个ParkingTicket列表。每个ParkingTicket代表一个ParkedCar
热门问题
推荐问题
最新问题