
A provocative question embedded in a friend-compatability checker created by a Java student in the Spring of 2018
Might we be friends? Decision logic exercise
Project specifications
- Flow diagram: Author’s paper folder and/or git respository contains a logic flow chart whose components accurately reflect how the program actually functions, including all branching logic. User info: Program asks the user for their name. Program then greets the user by name and displays the purpose of the program. Friend compatibility questions: Program asks the user at least 6 questions that require an integer or float response.
- At least half of those questions result in a conditional “reply” statement based on the user’s input. e.g. “oh, great, you like airports, too”
- Friend index: Program generates an overall numeric score based on the user responses which matches the flow chart logic for point adjustment.
- Friend potential determination: Program implements logic to determine the user’s potential friend compatibility based on the embedded weightings of each question. Program displays this information in some quantitative form such as conveying the percentage of possible points the user accrued.
Start Here: Jump to a section
wb_incandescentProject steps and code samples
wb_incandescentSample friend flow charts
check_boxCode sample: gathering integer input
bookCode sample: gathering text input
Project steps and code samples
- Flow chart on paper: Create a friend compatibility flow chart on paper like the ones shown below. Use our module guide on flow charting and if/else blocks as your reference. Remember, for our first draft, we'll only be gathering integer responses from the user. Once this works, you can work on String comparisons.
- Review sample code: Study the sample code with decision logic only that shows how to code up a single question with a hard-coded response
- Code it up: Write a draft version of your program like the previous sample in PyCharm:
- Test: Test your code ruthlessly! Make sure the logic works as the flow chart shows. Adjust your flow chart if you made mistakes.
- Comment your code sufficiently that another programmer of your level could read your code and understand its inner workings
- Sync: Make sure your hand-written flow chart matches how your program actually executes. Adjust one or the other to make them match.
- Share: Upload your code: Create a gitlab account if you don't already have one using this step-by-step guide.
Extension ideas
- After all the questions have been inputted, create code that prints a neat summary of each question's answer and how that answer factored into the overall compatibility score.
- Add one or more questions that ask the user for text input in response to a question. Check their response against possible responses and adjust the compatibility score accordingly. Check out these cool string operations in PythonLand for comparing on case, such as converting all to lowercase and then comparing.
- Make your code more robust by surrounding each input() call with try: and except: to provide the user feedback that the answer they submitted is invalid. For starters, you can just skip the question, or you can get fancier and use a while() structure to ask the question again if an exception occurs. Check out the w3 schools on try except in python. PythonLand also has a decent tutorial on exceptions.
- Enclose your entire program in a looping mechanism so multiple user's compatibility scores can be assembled and compared at the end of all the candidates. Write code that allows for the user to signal the end of new candidates and display summary and comparison data related to friend compatibility.
arrow_upward back up to contents
Sample program output and source code
When fully-baked, a sample program output can look like figure 4
Figure 4: Sample program interaction

arrow_upward back up to contents
wb_incandescentSample flow charts
Legacy students have authorized the sharing of their work for the benefit of future javas at CCAC. Use their work as launchpads for yours.
Zoom in on images |
On Win/Linux, Hold down control and engage your mouse's scroll ball to zoom. |
Figure 1: Dogs and gamers

Notice the creator's use of the term "Break" that appears multiple times in the flow system. Break signals a termination of the decision logic, and can occur as flow of execution winds through several paths. BUT, in Java if/else, we don't have a "break" or a goto some other line. We can't say: "Don't, go to the end of the program". Rather, we must build the pathway into the structure of our code by creating inner and outer chunks of logic. ALSO, the creator uses shorthand notes to show how various decision pathways impact a running total score that is used in a final comparison: "if compScore > 30"
Figure 2: Sports and Apple

Don't get too rigid about your shapes and symbols. This flow chart is a lovely programming plan for a four-choice decision tree. The author is using a running point total that is adjusted based on the user's response to the questions.
Figure 3: Meatballs

A decision structure need not involve only choices between yes/no or another pair of outcomes. This flow chart shows that a decision can be made between three or more possible values of a variable. This is done either with chained if-else blocks or a switch statement.
arrow_upward back up to contents
(c)2023 technologyrediscogvery.net | content can freely reproduced according to the site's content use agreement.