I'm creating a simple game in Netbeans but I've come across a problem, when I've 500 coins and I try to add more, the total coins value will go to -1 therefore I think I need a else if statement in my code to stop and display a error message but I'm not sure how to write it?

Click Here

Click Here

1 Year
Discussion Span
Last Post by Schol-R-LEA

As stultuske aleady said, cross-posting is generally considered poor nettiquete, as it leads to a duplication of effort, and anyone who sees the posts on both groups (and there usually are several who frequent both SO and Daniweb) will get tired of seeing the same posts repeated.

Also, as pointed out in the SO replies, posting an image of the code rather than the the code as editable text is also a problem; you don't want to make it difficult for the respondents to copy and re-write the code, as they usually will have to make changes to it to test it and for their reply to you. For something this size, it makes far more sense to paste into the post instead (though don't forget to use the Code button at the top when you do so. Much larger code sections, yes, you might want to have a link to the code instead, though you generally would be better off posting just the part of it that seems to be causing the problem in that case.

Edited by Schol-R-LEA


Is there a real need to have two separate totals? It seems to me that you could just use ocoins (preferably with a better variable name) and write:

    if (ocoins < MAXCOINS) {
        lblpoints.setText(String.ValueOf(MAXCOINS - ocoins);
    // ...

... where MAXCOINS is a class constant set at the beginning of the class:

static final int MAXCOINS = 500;

Note the use of the increment operator (++), also.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.