A method I'm using requires loops, and I have managed to work myself into a corner trying to split up the loops up by adding new methods. I've pasted part of my code below. I'm currently receiving the error message "missing return statement" and although I realise why this is happening I am unsure as how to continue. Any help or suggestions would be appreciated! Thanks.
public String addJob(String cust,boolean onSite, boolean sHand, String lang)
{ int nt = 100;
if (customers.containsKey(cust))
{
if (0 >= getCustomerCredit(cust)) {
return " Customer over credit limit "; }
if (nt >= getCustomerCredit(cust))
{
Job jb = new Job(cust, onSite, sHand, lang);
job.put(jb, getNewJobNo());
if(lang != "English")
{
isStaffAvailableWork(trnsltr);}
if(sHand == false)
{ isStaffAvailableWork(clk);
}
else { isStaffAvailableWork(typst);
}
}
}
else {
Customer c = new Customer(cust);
customers.put(cust, ntnt);
Job jb = new Job(cust, onSite, sHand, lang);
job.put(jb, getNewJobNo());
if(lang != "English")
{
isStaffAvailableWork(trnsltr);}
if(sHand == false)
{ isStaffAvailableWork(clk);
}
else { isStaffAvailableWork(typst);
}
}
}
public String isStaffAvailableWork(Staff stf)
{
if (staff.containsKey(stf)&&(stf.isStaffAvailable()==true))
{
jb.setJobStatusOnGoing();
stf.setStaffBusy();
jobNoAndstaffId.put(staff.get(stf), job.get(jb));
return "Staff allocated: " + stf;
}
if (staff.containsKey(stf)&&(stf.isStaffAvailable()==false))
{
jb.setJobStatusWaiting();
return "Job Waiting";
}
else return null;
}
Your question is somewhat broad, but your issue is that your function somehow isn't giving back a value. Every line from which a function can exit must return something.
public bool foo(var x)
{
if(x == 0)
{
// Returns successfully.
return true;
}
else if(x != 0)
{
// Didn't return anything.
}
// Also didn't return anything.
}