System.out.println not working in my method...?
/**
* This will add a contract to the firm
*/
publicvoid createContract(String contractId,int contractDays, String typeOfContract)
{
for(Accountant anAccountant : accountants)
{
if(getNumOfAccountants() >= 1){
if(anAccountant.getExpertise().equals(typeOfContract)){
if(anAccountant.getIsWorking() ==false){
Contract newContract =new Contract(contractId, contractDays, typeOfContract);
contracts.add(newContract);
System.out.println("A contract has been created, the contracts name is " + contractId);
System.out.println("The price of the contract is " + (anAccountant.getDailyRate()*1.21));
System.out.println("The duration of the contract is " + contractDays +" days");
System.out.println("The type of the contract is " + typeOfContract);
anAccountant.setIsWorking();
}
else{
System.out.println("There are no suitable accountants in the firm to match the requirements");
}
}
}
}
}
I am having trouble with the last else statement, the system.out.println("There are no suitable accountants in the firm to match the requirements");
This isn't getting called if the above "if" statements arn't correct.
For example i want this statement to be printed if there arn't enough accountants in the firm.
Can someone help.
Thanks alot
Message was edited by:
Capsud
[2288 byte] By [
Capsuda] at [2007-11-26 22:51:15]

/**
* This will add a contract to the firm
*/
public void createContract(String contractId, int contractDays, String typeOfContract)
{
for(Accountant anAccountant : accountants)
{
if(getNumOfAccountants() >= 1)
if(anAccountant.getExpertise().equals(typeOfContract))
if(anAccountant.getIsWorking() == false)
{
Contract newContract = new Contract(contractId, contractDays, typeOfContract);
contracts.add(newContract);
System.out.println("A contract has been created, the contracts name is " + contractId);
System.out.println("The price of the contract is " + (anAccountant.getDailyRate()*1.21));
System.out.println("The duration of the contract is " + contractDays + " days");
System.out.println("The type of the contract is " + typeOfContract);
anAccountant.setIsWorking();
}
else {
System.out.println("There are no suitable accountants in the firm to match the requirements");
}
}
}
Ok that is the code i have now but that statement is still not working.
a few pointers:
get rid of that nested conditional logic. as demonstrated, it's not particularly clear or readable code. deal with each condition one by one
you don't need to do this:
if(anAccountant.getIsWorking() == false) {
boolean expressions evaluate to true/false already. this will suffice:
if(anAccountant.getIsWorking() ) {
while we're on that subject, why not just call the method isWorking, rather than getIsWorking? naming conventions exist for a reason!
why are you calling getNumOfAccountants in every iteration of your loop? that's not going to change in the space of a few clock cycles, is it?
rather than try to fix this, I strongly suggest you simply throw it out and start again. work out exactly what you want the code to do. this looks like classic guess-driven development