This post is based on an unofficial guide. For best results, it is important that you are extremely familiar with Chapter 51. This post assumes that the you are aware of the structure of the pre-release material. Information beyond the video is tailor made for version 21.
Data Declaration
Data Type | Data Name | Explainer |
String[ ] | memberNames | An array to store the names of each member as a string. |
int[ ] | memberVolunteerAreaCodes | An array to store the area codes of each volunteering member as an integer: 1, 2 or 3. In the case of non-volunteering members a 0 will be stored. |
int | PIER | A constant that stores one single area code as an integer. |
int | areaCode | A variable that stores the area code chosen by the user. A range validation check is performed on it to make sure that the value is not less than one and not greater than three. |
Expressing Algorithms
Below is a flowchart that illustrates how the user of the program can input a category to get a sub set of members. Each category filters the list of members by a particular property e.g. whether they are volunteering or whether or not they have paid the fee. It is important that the user inserts a valid category of type integer. Therefore, the program must perform a range check validation to make sure that the category is between 1 and 6. In case that the user inputs a number that is not a category, then he is given the opportunity to re-enter a valid choice. This can be done by using looping structures that repeats input prompts until a valid category is entered. Finally, conditional statements are used in order to perform filtering of a particular category, for instance, if a category is three then members who volunteer at the gift shop are filtered out. The name and surname of these members are displayed back to the user.
In order to keep the flowchart concise implementation details about the filtering has been omitted. To explain how filtering can be done it might be better to use pseudocode. Since we have stored member properties in separate arrays we can easily implement a selection technique. The first and last names of each member are stored in an array named MEMBER_NAMES and the volunteer area codes of each member are stored in an array named MEMBER_VOLUNTEER_AREAS. Note that both arrays are of the same size because to get information about a single member we have to use the same index. In order to display the names of members that volunteer at the gift shop we loop through every element in MEMBER_VOLUNTEER_AREAS and use a conditional statement to check if the value is equal to the AREA_CODE_GIFT. If the condition is satisfied then the respective element in MEMBER_NAMES can be displayed.
Where can I see some code please?
Follow this link to see a solution in Java.
Comentarios