В моем коде мне было приказано вернуть объект в моем методе GetCustomer
в моем классе CustomerManager
из класса Customer
.Я новичок в объектно-ориентированном программировании, поэтому у меня нет идей, как это сделать.Может кто-нибудь мне помочь?
Класс менеджера по работе с клиентами
public class customerManager
{
private static int currentCusNo;
private int maxCustomers;
private int numCustomers;
customer[] cList;
public customerManager(int maxCust, int seed)
{
currentCusNo = seed;
maxCustomers = maxCust;
numCustomers = 0;
cList = new customer[maxCustomers];
}
public bool addcustomers(string fN, string lN, string ph)
{
if (numCustomers > maxCustomers) return false;
customer m = new customer(fN, lN, ph, currentCusNo);
currentCusNo++;
cList[numCustomers] = m;
numCustomers++;
return true;
}
public int findCustomer(int cusID)
{
for (int x = 0; x < numCustomers; x++)
{
if (cList[x].getID() == cusID)
{
return x;
}
}
return -1;
}
public bool customerExist(int cusID)
{
for (int x = 0; x < numCustomers; x++)
{
if (cList[x].getID() == cusID)
{
return true;
}
}
return false;
}
public string customerlist()
{
string y = " ";
for (int x = 0; x < numCustomers; x++)
{
y += "\nFirst Name: " + cList[x].getFirstName() + "\nLast name: " + cList[x].getLasttName() + "\nCustomer ID: " + cList[x].getID();
}
return y;
}
public customer GetCustomer(int cID)
{
for (int x = 0; x < numCustomers; x++)
{
}
}
}
}
Класс по клиенту
public class customer
{
private int customerID;
private string firstName;
private string lastName;
private string phone;
public customer(string fN, string lN, string ph, int cId)
{
customerID = cId;
firstName = fN;
lastName = lN;
phone = ph;
}
public int getID() { return customerID; }
public string getFirstName() { return firstName; }
public string getLasttName() { return lastName; }
public string getPhone() { return phone; }
public string toString()
{
string s = "";
s +="First Name: " + firstName + "\nLast Name: " + lastName + "\nPhone: " + phone + "\nCustomer ID: " + customerID;
return s;
}
}
}