Tag Archives: Java

Java.writeMyCode() – Vol. I – BigInteger

Programming contests are very popular in Texas and most areas of the state host at least 1 each month.  They are great vehicles through which to increase enrollment and to get students excited about “cranking code”.

It is very important to know what tools are available in your language before attending a contest.  If the language being used provides a tool to help solve a problem, then teams should use that tool as part of the solution instead of writing every single line of code from scratch.  I stress to my students to never re-invent the wheel.  If the language already has a perfectly good wheel, put that sucker on your car and hit the road.

Java has lots of cool stuff built-in.  BigInteger is a class that has many methods in it that can make solving certain math related contest problems much easier.  BigInteger contains an isProbablePrime() method.  This is quite useful at contests.

Using BigInteger in Java

Using BigInteger in Java

It is equally important that student understand the algorithm being used to determine if a number is prime and how to create such an algorithm.  Learning the fundamental algorithmic concepts is critical to being a well rounded CS student, but for contest purposes, it is all about speed and accuracy so using built-in methods where possible helps save time and prevent errors.

Teaching AP Concepts in Scratch – Vol II – Searching

A typical linear search algorithm consists of some variables, an if-statement, some type of loop, and of course a list.  The search may be examining the list and looking for a specific value or some type of thing, like a specific type of creature, the prettiest princess, or an animal in a game.  I do not write games about pretty princesses, but I do have students that like to do that.

The AP A exam tests a student’s ability to solve problems and formulate algorithms.  The exam does use Java as a testing vehicle, but does not test specific syntax details of the Java language.  First and foremost, the AP A exam is focused on testing a student’s problem-solving ability.  Searching a list requires a certain amount of problem solving ability at a very basic level.

Searching through a list for something is a very important Computer Science concept and one that is tested on the AP A exam.  Typically, the AP exam free response will ask a student to write an algorithm to search a list for something.  The multiple choice component of the test usually contains a question or two focused on searching as well.  Students need to understand this concept very well.

Searching in Scratch and in Java.

Searching in Scratch and in Java.

Writing a search in Scratch is relatively the same as writing a search in any language or environment.  Students still have to combine some variables, a loop, and an if-statement together to process a list in order to solve the problem.  The main benefit of doing this in Scratch first is that students can just focus on the problem as they have to spend considerably less time on the details of typing in all of the pieces.  Scratch does not require that students focus on syntax details so students can concentrate solely on how to solve the problem.  After mastering the concept in Scratch, it will be much easier to crank out a solution in a text-based language like Python, Scala, PHP, Ruby, or even Java.

Scala is a pretty slick language by the way.  A good friend at Rice University suggested I check it out.  It is pretty cool.

Using Scratch BYOB makes creating a search in Scratch a bit slicker as you can create your own blocks and pass parameters.  This adds in a bit of abstraction that you do not have in the non-BYOB version of Scratch.