Getting Started on Problems

Several of you mentioned in the background survey responses that you get stuck "getting started" on a problem. Here are steps/questions to ask yourself, that align with what many of you learned in CS1101:

  1. Identify what kinds of data is involved in the problem (based on the description). For each kind of data, either note an existing class/Java type (i.e., int, string) that captures that data, or define a new class that captures the data. Depending on the proble, you may need to create more than one class.
  2. To sanity check your data setup, write 1-2 concrete examples of the data. For Java, define these these in an Examples class. If your data involves classes, this means you will create objects for specific values of the data.
  3. If the problem asks you to write a function/method, figure out which class the method should go in (which class has the most essential data for the computation at hand)? The fields of that class are available to the method for free; any other data needed for the method must be a parameter/input to the method.
  4. Try writing just the header (return type and inputs) for the method. Comment these out until you are ready to fill in the body of the method.
  5. Write one or two test cases that illustrate how the method should behave. These go in your Examples class.
  6. Fill in the body of the method. (I understand from comments that some of you feel stuck here -- we will work on strategies for this in the coming weeks.

Note that the first task here is NOT "writing code". It is understanding the question being asked. Articulating the data, making an example of it, and articulating what the method should do are essential precursors to being able to write code. When you see classmates able to just dive in and write code, they are able to do the data and method comprehension steps in their heads, so they jump to code writing. You cannot hope to produce useful code for a problem you don't understand. Articulating data and desired behavior are how you come to understand a problem.

These steps are designed to help you consider a problem one aspect at a time, rather than all at once. All at once, there are often too many issues to consider, and your head can start spinning as you try to sort them all out simultaneously. Focus on one aspect at a time (we've staged the aspects in this order for a reason (they build on each other). If you can train yourself to focus on one step at a time, you make the problem more manageable.

As part of focusing, ignore interfaces and abstract classes at first, and just focus on the core classes that you need for the data in the problem. You can add interfaces and abstract classes later. They build upon the core classes that capture the data in a problem. Get those right first.