Hey everyone I'm working on a project where I'm making a lemonade stand and I've reached a point where I'm a little stuck. What I'm trying to do is get my program to run a method to make lemonade (makeLemonade) if and only if I have enough ingredients to make the lemonade, but I keep getting an error from the tests provided for me that tells my lemonade is being made even when I don't have enough ingredients. Here's the code I have right now for the if statement that's giving me some trouble. I've tried using && and || along with different mixes of >= and > to no avail so far.
public int makeLemonade()
{
if (lemons >= 6 && gallonsOfWater >= 1 && cupsOfSugar >= 1
&& emptyGlasses >= 8)
{
lemons = lemons - 6;
gallonsOfWater = gallonsOfWater - 1;
cupsOfSugar = cupsOfSugar - 1;
emptyGlasses = emptyGlasses - 8;
glassesOfLemonade = glassesOfLemonade + 8;
return glassesOfLemonade;
}
else
{
return 0;
}
This is the error my test is giving me right now
"Test of method makeLemonade failed for activty 3.
The following code was executed:
LemonadeStand ls = new LemonadeStand(5, 2, 2, 16, 1.1);
ls.makeLemonade();
Fields were modified even though there was not enough lemons available to make lemonade."
Thanks for any replies and advice that can guide me into the right direction, I do appreciate it.
Aucun commentaire:
Enregistrer un commentaire