COMP3200 Anonymous Questions and Answers Keyword Index |
This page provides a keyword index to questions and answers. Clicking on a keyword will take you to a page containing all questions and answers for that keyword, grouped by year.
To submit a question, use the anonymous questions page. You may find the keyword index and/or top-level index useful for locating past questions and answers.
Keyword reference for method-addMoney
2024 |
Submission reference: IN3671
For the second method addMoney am I supposed to write an if method as well? because I have written the code as a ++ and I didn't come up as an error so I'm not sure if I need to write an if
The assignment says, 'The parameter value must be added to the amount field, but only if the parameter's value is greater than zero.' So, there will need to be an if-statement. Be careful about the way you increase the amount
field because using ++ only adds 1 to a variable and you want the method to add whatever value is in the parameter into amount
. The parameter's value will not necessarily be 1. Use the object inspector to check that the field is correct after the call.
Keywords: assign1 , method-addMoney
Submission reference: IN3669
For the assignment, when it says write a method addMoney that takes one int parameter, what is supposed to be in the parameter is it the name of the field or you can name it anything?
You can call the parameter whatever you like, but I recommend not calling it 'amount' to avoid a name clash with the amount field. Give it a name that relates to the fact that it is an amount of money being put in the money box.
Keywords: assign1 , method-addMoney
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. |