0

I'm stuck on one of the methods I have to write. I try to write the method for disabling a button when the product is out of stock. However nothing I try is working. I have to following lines as a pseudocode:

// getting the information about the stocking (how many products are in stock, listed in the controller class)

// making an if statement:

// if 0 products in stock than button should be disabled

// else button should be enabled

But I don't know how to continu. The other exercises (so also the finishing ones) all work. Only this one doesn't work out.

Share a link to this question (includes your user id)
| edit | | close | delete |
0

You only have to fill in the given method setButtonOutOfStock(). The controller handles the inventory, so you do not have to worry about that (as explained in the assignment). The MachineUI class only has to do things for the Controller. So when the Controller thinks a product is out of stock, it will call the setButtonOutOfStock() method to Make the MachineUI show that in the UI.

The 'skeleton' of this method is already given:

... setButtonOutOfStock(int ...)

Lets say the parameter is variable 'button' (fill that in on the ... of the parameter). That is also used in the method setButtonLabel(). So use that as an example. What this method should do, is "disable button button". You can determine the button with an if-statement, just like in method setButtonLabel(). So in pseudo code that would look like, for the first button:

if (button==0) call method of button to disable it

Then, of course, it should work for the other buttons also, so add an else, just like in setButtonLabel().

The "call method of button to disable it" uses the method setEnabled(false) of the button, as explained in the assignment.

Share a link to this answer (includes your user id)
| edit | delete |

Your Answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.