dimanche 22 mars 2015

Boolean method is not checking if statment

I'm trying to write boolean method but it doesn't work



public boolean addPresent(Present present)
{
if(totWeight+present.getWeight()<=maxWeight)
{
presents.add(present);
presents1.add(present);
return true;

}
for(Present pres : presents1)
{
totWeight+=pres.getWeight();
}return false;
}


It's working if I write this method:



public void addPresent(Present present)
{
if(totWeight+present.getWeight()<=maxWeight)
{
presents.add(present);
presents1.add(present);
System.out.println("true");

}else
{ System.out.println("false");
}
for(Present pres : presents1)
{
totWeight+=pres.getWeight();
}
}


How should I make boolean method for it?


Aucun commentaire:

Enregistrer un commentaire