Consider the problem of maintaining statistics for major league baseball. One person could calculate the average number of runs per game. Another person could find the number of innings each player has played in the game in a season. Yet another person could calculate the ratio of hits to at-bats for each batter. Each person would use various productivity tools to gather authentic informa- tion for the application. In a computer program, these smaller jobs are handled by lines of instructions called procedures or methods. Recognize Patterns Problems that are good candidates for computer pro- grams have patterns in the solution. Pattern recognition is the skill of identifying and isolating any repetitions. Repeti- tions can be inside the problem being solved. They also may be patterns recognized from earlier solutions. Either way, recognizing these patterns helps to create or reuse a solution. Figure 1-4 shows a player taking a shot on goal in a soccer match. Suppose the problem is finding the average distance between a player and the goal line when a goal is scored. Finding an average distance to the goal is the same pattern as finding a grade average in math class. Recognizing this pattern helps you to see that individual data points need to be collected, the points totaled, and the total divided by the number of data points. Collecting the data points is a human action. Inputting them into the computer, totaling them, and dividing them are steps to use in a computer program. Generalize Patterns Abstraction is the act of generalizing a pattern. It is taking specific pat- terns in a problem and relating them to other similar or identical patterns. For example, consider the following patterns. • the date two days from today • the number of people in a family after twins are born • the next even number These patterns can all be generalized with the algebraic expression x + 2. After all, that is the whole point of algebra, to generalize. Computers can solve prob- lems if they can be generalized in an algebraic expression. Once a pattern is identified and generalized, the solution of an equation is essentially the same for all algebraic equations: look at the equation and figure out how to isolate the variable. When you think of abstraction, think of algebra. One of the most-asked questions in algebra is, “When am I ever going to use this stuff?” Here is the answer: you will use it in computer programming. In a large-scale statistics program, patterns can be identified. For example, sums of numbers are required, averages must be calculated, individual stats are tracked as well as team stats, and more. Generalizing these patterns into a sum method or an average method allows the problem-solver to reuse these methods for each specific case in the program. Write an Algorithm Once a problem is decomposed into small steps that a computer can per- form, the computer program can be written. For example, to calculate an aver- age of a set of data, the small steps are: 1. Enter the data. FYI Writing general expressions that can represent a specific situation and then applying the laws of algebra to find the value of the variable is the main purpose of algebra. Advanced algebra is called analysis. Oleksandr Osipov/Shutterstock.com Figure 1-4. This player is taking a shot on goal. Suppose the problem is finding the average distance between players and the goal line when a shot on goal is taken. Copyright Goodheart-Willcox Co., Inc. 8 Introduction to Computer Science: Java Programming