Question #1 on Exam - Methods + Control Structures
- Typical questions from this category require creation of methods that satisfy specific requirements through the use of expressions, conditional statements, and iterative statements.
- question typically consists of 2 parts
Part (a):
- this question usually requires you to write a certain method that fits the given test cases and “rules” provided by the problem
- rules + test cases may be provided as a table or as example method calls
- a precondition is usually provided by the problem - a precondition is something that has to be true about the parameters of the function.
-
a boilerplate segment containing a method declaration is also given
Common/General Penalties:
- some of the mistakes that do not have any penalties are mainly syntax + spelling issues (however, the code should be easily understood)
Satisfying the Rules:
The rules that need to be satisfied by the method typically require the use of one or more of the following categories:
- conditional statements
-
iterative statements
Example of Conditional Statements:
Example of Iterative Statements:
Example Question:
Example Answer:
Generalizations/Reminders:
- All possible/needed iterations need to be accounted for.
-
Java does not allow you to use the ‘==’ sign for comparison of strings; use the equals method instead.
Part (b):
- this part is similar to part (a) and typically asks you to write a method that satisfies the given set of rules.
- it may build upon the method created in part (a) (when this is done, it allows you to assume that the method in part (a) works as intended)
Overall Summary of Scoring Guidelines:
- Incorrect parameter types and the order of paramters in the method declaration will not be given credit