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

Extension class activity for java module exploring control of flow and user input.

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

  1. 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.
  2. 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
  3. Code it up: Write a draft version of your program like the previous sample in NetBeans: don't worry yet about user input. Make sure the logical paths work before adding extra complexity.
  4. Study user input sample: Study this sample program that generated the sample output below. This class uses an object called a Scanner to read input from the keyboard. We don't know much about object creation yet, but you can get the gist of how we read in data on with it and store it in a properly typed variable.
  5. Add user input: Adjust your code to use a Scanner object to interact with the user based on the code samples in the previous item.
  6. Test: Test your code ruthlessly! Make sure the logic works as the flow chart shows. Adjust your flow chart if you made mistakes.
  7. Comment your code sufficiently that another programmer of your level could read your code and understand its inner workings
  8. Prepare: Ensure that the license header and @author tags are correct
  9. Sync: Make sure your hand-written flow chart matches how your program actually executes. Adjust one or the other to make them match.
  10. Print your code from directly inside netbeans and place it in your class folder.
  11. Share: Upload your code: Create a git-hub account if you don't already have one using this step-by-step guide. Inside that account, create a repository for CIT-111, and upload the .java file containing your working program. THis is described in agonizing detail in the guide.

Extension ideas

Nested logic

Study this code with nested if/else blocks. Add this kind of logic to your program.

String input

Read in our module guide about gathering String input. Study this code with String input. Add this kind of logic to your program.

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
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
student flow chart samples
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
student flow chart samples
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
student flow chart samples
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)2018 technologyrediscogvery.net | content can freely reproduced according to the site's content use agreement.