id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

orion.a.smith@gmail.com apcsa-primitives

Description:AP CS A - Primitive Data (Unit 1)

Primitive Data problems (AP Computer Science A)

These problems are doable for most students with a working knowledge of primitive data types, plus a little understanding of if (conditional) statements and maybe some logical operators like && (and), || (or), ! (not). So they could be assigned, with a bit of work to prepare for them, in Unit 1. Or, they could be a dead simple set of tasks in Unit 3.

I think that most teachers should feel OK giving these problems to students in the first unit of the course, since they start out literally as gentle as can be imagined (return the input unchanged) and build to a still-mild difficulty level by the time they're done.


Creating consistent CodingBat solution code

Remember the structure of a CodingBat solution, to keep you from skipping important information:


Step 1: create an output variable and assign it an initial value.  This should be of the same data type as the method you are filling out, so if the method signature is public boolean areMyEyesClosed(int amountOfLight), the data type is boolean and you should create an output variable like
  boolean output = true;
You can name your output variable whatever you like.

Step 2: go to the bottom of the method and return your output variable. This is totally simple, make the last line of your method read as

  return output;
(assuming that your variable is called output)

Step 3: read the actual problem description and use logic to assign a new value to your output variable. This is often going to include some if statements and, in later sets of problems, loops. Some problems are clearly more complex than others. This code should go in between the first statement (declaring an output variable) and the last statement (returning your output variable). In our example, the problem might state that any positive amount of light indicates that your eyes are open. So the code could look like the following.

  if (amountOfLight > 0) 
  {
    output = false;
  }

So, complete code for this example method might look like the following. Your code probably won't have the comments in it, but it could.

public boolean areMyEyesClosed(int amountOfLight) {
  // step 1
  boolean output = true;
  
  // step 3
  if (amountOfLight > 0) 
  {
    output = false;
  }
  
  // step 2
  return output;
}

This is not the most efficient way to solve a problem, but it keeps you thinking about the important idea that each CodingBat problem is working its way toward returning an output variable of a certain data type. In AP Computer Science A, remembering this method structure may save your behind on a handwritten free response question.


Problems with no if statements

apcsaPrimitivesReturnInput 
apcsaPrimitivesDoubleInput H  
apcsaPrimitivesNegateInput 
apcsaPrimitivesRemainder3 H  
apcsaPrimitivesReturnMod H  
apcsaPrimitivesLastDigit H  
apcsaPrimitivesStripDigit H  
apcsaPrimitivesAddOperands H  
apcsaPrimitivesMultiplyOperands H  


Problems requiring if statements

apcsaPrimitivesCheckAnd  apcsaPrimitivesCheckPositive H   apcsaPrimitivesIsMultipleOfThree H   apcsaPrimitivesRemainderSame H   apcsaPrimitivesMultiplyOrAddOperands1 H   apcsaPrimitivesMultiplyOrAddOperands2 H   apcsaPrimitivesOrDoubleOperands H   apcsaPrimitivesIsChilly  apcsaPrimitivesFindGreater H   apcsaPrimitivesFindAbsoluteGreater H   apcsaPrimitivesFindAbsoluteLesser  apcsaPrimitivesFindGreaterRemainder H   apcsaPrimitivesIsNumSum H   apcsaPrimitivesSameDistance  apcsaPrimitivesLargerBySmaller  apcsaPrimitivesSameMagnitude 
Authoring docs

Copyright Nick Parlante 2017 - privacy