Posts

Showing posts from March, 2009

Shuffling numbers

One of the tiresome things about computers in general is the difficulty they have with recognising numbers. If you say to a child "add two and two" they will add the two numbers and give you four. If you say to the child "write two and two" they will write the string "two and two" or "2+2". If you subsequently asked them to solve, they will convert the string back to an equation and give you four again. My first instinct after writing code which successfully shuffles strings was to extract numbers from them. Java has various methods for converting strings to numbers. A problem with all of them in my experience is that they are fussy about the string you pass to them for conversion. Accidentally appending non-numeric characters, like commas or brackets, usually generates exceptions. Coding to handle these exceptions is fraught with problems and messy. After much thought I decided that rather than shuffling strings and converting the

Shuffling lists and arrays

My task is to add some elements to a list, shuffle it, and then generate a sublist. The Collections Interface includes methods which can be used on all the subtypes of collection. Then each type of collection has some additional methods, specific to that type. Looking down the interface, I could use the add method to add elements one by one, the addall to add all the elements of another collection. The array operations include toArray, which presumably means putting elements in an array not taking them from it. The Set Interface on first glance looks very similar to the generic one. The List Interface has the sublist method but as with the others, the group add feature seems to require you to add from another collection. So how do you populate the first collection? The answer is given halfway down the page, and I'll quote from the page because there is nothing to be gained by paraphrasing: "The Arrays class has a static factory method called asList , which

Algorithms versus arrays

I've often wondered why so many forum questions relate to poker games. It turns out that an example of how to use the List interface is shuffling cards and dealing a hand or hands from the deck. This is not only pleasingly clever, but it is also exactly the kind of operation I am trying to mimic. I am not shuffling and dealing cards but I am wanting to shuffle and deal from a collection of test items. I am a bit embarrassed to admit that I am planning to use hard coded arrays to generate test items. The thing I boasted most about my school math software when I first produced it was that it used algorithms to generate test items rather that selecting from a finite list. There are two problems with algorithms. One is the issue of repetition. The second is that of designing an algorithm to generate a precise level of difficulty. When I was doing my research I collected a lot of data on which math questions children find easy. I even used Rasch methodology

Collections

This post is a bit of a non-sequitur. The thing is I posted a theory question and the reply took me back to a theory trail , which I had previously omitted. The first odd this about this trail is that it has a by line, and none of the others do. What does that mean? I think it means it is esoteric - that it was added late by someone with a special interest in the subject. So what does it say? I quote: "This chapter describes the Java Collections Framework. Here you will learn what collections are and how they can make your job easier and programs better." That sounds good. I posted the question because I had written some clumsy code in VB, and rather than just copying it out in Java, I wanted to use a different approach, and do the job better. The second paragraph of the introduction says: "If you've used the Java programming language — or just about any other programming language — you're already familiar with collections." That se

A stopwatch timer

Of the three areas I need to research, a timer, dynamic graphics, and storing data, I shall begin by looking for a timer. I have seen reference to one but I can't remember where. I notice a link to search the tutorial in the top right hand corner of the page. I search "timers". I am led to a page on the Swing Timer, which begins by warning "Don't confuse Swing timers with the general-purpose timer facility that was added to the java.util package in release 1.3. This page describes only Swing timers." As it happens I am interested in "the general-purpose timer". It would be nice if there were a link on this text, but the is not, so I search "general-purpose timer", and guess what: I am led to the same text on the same page. There is a link to the javax.swing.Timer ) in the javax API so I follow that to look for clues. Certainly I can see where I might use it when I have my graphics going, but just now it is not what I want. So I

Full Circle

My last entry took me full circle. I began this blog because I had written a few lines of code, but I had not read the instructions well enough to deploy either a stand alone application or an applet embedded in a web page. Now that I have a rudimentary applet running in a web page I am where I was when I began. For the last few days I have been writing code again. There has been nothing to write about because there was no-one but myself to blame for any errors or confusion. I have had moments of frustration with NetBeans. It takes too much control. But for now the benefits outweigh the annoyances. I have thought it might be nice to find a VB-Java dictionary, like a French-English dictionary, but then I took advantage of the NetBeans code writing aids to answer my questions without searching too far. The question is where to go next in the Java Tutorial to make my Java applet more like Windows client-server application it sets out to mimic. There are three areas I need to r