Reputation: 69
I am doing an exercise about a flight and customer class. I was wondering about for the method under flight class which is used to add passenger (using customer Manager class ). How should I add this method to add customer in the flight class but using the method in the customer manager class?
class CustomerManager
{
public static int currentCxNum;
private int numCxs;
private int maxCxs;
private Customer[] myList;
public CustomerManager(int seed, int maxCx)// seed=starting point
{
currentCxNum = seed;
maxCxs = maxCx;
myList = new Customer[maxCx];
}
public bool addCustomer(int cID,string fN, string lN, string cNum)
{
if (numCxs >= maxCxs)
{
return false;
}
else
{
Customer a = new Customer(cID, fN, lN,cNum);
currentCxNum++;
myList[numCxs] = a;
numCxs++;
return true;
}
}
}
class Flight
{
protected int flightNum, masSeats, numPassengers;
protected string origin, destination;
protected CustomerManager[] cxList;
public Flight(int flNum, string orig, string dest, int maxSe)
{
flightNum = flNum;
origin = orig;
destination = dest;
masSeats = maxSe;
}
public bool addPass(Customer cx)
{
CustomerManager bb = new CustomerManager(100,200);
if (numPassengers <= masSeats)
{
if (!bb.customerExist(cx.getID()))
{
bb.addCustomer(cx.getID(), cx.getfName(), cx.getlName(), cx.getcxNum());
numPassengers++;
}
return true;
}
return false;
}
Upvotes: 0
Views: 102
Reputation: 543
I think what you want to do is instead of having an array of CustomerManager
objects you have one CustomerManager
object per Flight
object. The CustomerManager
object then manages a list of Customer
objects. So then the Flight
object's addPassenger
method would take a Customer
and then call the CustomerManager
's addCustomer
method. Something like:
public class Flight
{
protected int flightNum;
protected string origin, destination;
protected CustomerManager cxList;
public Flight(int flNum, string orig, string dest, int maxSe)
{
cxList = new CustomerManager(0, maxSe);
origin = orig;
destination = dest;
flightNum = flNum
}
public bool addPass(Customer cx)
{
return cxList.addCustomer(cx.getCID(),cx.getFN(), cx.getlN(),cx.getcNum());
}
}
Upvotes: 1