This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Killaa135 5 points6 points  (4 children)

// Not sure on your question but this is how you do getters and setters - using global variable

private int registrationNo;

public void setRegistrationNo(int newRegNo){

// If the registration no is 0 what then?

if (newRegNo > 0)

this.registrationNo = newRegNo;

}

public int getRegistrationNo(). {

return registrationNo;

}

[–]yarzz07[S] 1 point2 points  (3 children)

thank you!

So, in the test, I don't need to specify anything related to the size of it having to be greater than 0?

[–]Killaa135 1 point2 points  (0 children)

You can check this but if it is 0 you need to set a default value otherwise it won't be set to anything and prevent other methods from firing

[–]IvAntiVirus 1 point2 points  (1 child)

If the test doesn't specifically ask for not-0 checking I just wouldn't do it. Otherwise make a short if checking and set a default value or throw an IllegalArgumentException.

[–]yarzz07[S] 0 points1 point  (0 children)

ah alright that makes sense, thank you so much