Using JavaFX for your IB Computer Science IA

If you are comfortable using IntelliJ with/without Gradle or Maven then fine, but I find that sometimes these tools mask what is going on behind the scenes. For that reason, I often like to use a simple text editor for small projects. To get JavaFX working without a build manager, follow these simple instructions.

Download a version of JavaFX. I downloaded the Linux SDK (version 12) from here: https://gluonhq.com/products/javafx/

Unzip it to a place on your file system that you use to store java libraries. I just put mine in my home directory.

Create Main.java with the following code:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.stage.Stage;

public class Main extends Application {
    public void start(Stage stage) {
        Scene scene = new Scene(new Label("Foo"));
        stage.setScene(scene);
        stage.show();
    }
}

 
In order not to have to make changes to your CLASSPATH you can add arguments to the compiler and the JVM.

Compile with

javac --module-path ~/javafx-sdk-12.0.2/lib --add-modules javafx.controls Main.java

Run with

java --module-path ~/javafx-sdk-12.0.2/lib --add-modules javafx.controls Main

Other modules may be required as you use more features of JavaFX.

IB Computer Science IA: Word Count Advice

The word count is 2000. If you go over this then the moderator has the right to stop marking the extra. Some parts of the IA have no word count but there are nuances.

What is not included in the word count:

  • The success criteria (in Criterion A)
  • The record of tasks (Criterion B)
  • The design overview (Criterion B)
  • The video, obviously (Criterion D)

This means that the only parts of the IA that do have a word count are:

  • Criterion A (all except the success criteria)
  • Criterion C
  • Criterion E

Since Criterion A and Criterion E are both worth 6 marks, and Criterion C is worth 12 marks, it makes sense to divide the word count accordingly:

  • Criterion A and E: 500 words each
  • Criterion C: 1000 words

A few words of advice:

  • Source code should be included in an appendix and obviously does not contribute to the word count.
  • Diagram annotations will not contribute to the word count unless they are flagrantly being misused to cram in extra content.
  • The design overview (Criterion B) should not include extended writing; it should be mostly diagrams, tables, schematics, flowcharts, pseudocode, etc. If you add a lot of explanatory text to Criterion B then the moderator is free to add it to the word count.

Please free to ask any questions in the comments section.

IB Computer Science Case Study 2019: A Word of Warning

When students are faced with a research task, a common strategy for weaker students is to just “google it” and take notes on the first few search results. Another poor strategy that affects IB Computer Science students is to exclusively revise from one IB Computer Science website, on the assumption that everything on it is correct.

While examining this year’s Case Study, “A new computer aided dispatch system for Bangbai”, I found that a great many students were giving the same, wrong answers to some of the questions. In some cases students were giving the same answers, word-for-word.

I decided to see if I could find where these answers were coming from and I tracked them down to one IB Computer Science website. Reading through the case study notes on that site, I found a whole range of notes that were quite wrong. It is bad luck that a question came up this year on which this website’s notes were particularly bad. I won’t reveal the question or the name of the site but suffice it to say that I have awarded zero marks to literally hundreds of students this year because they wrote down, word-for-word, what was written in the case study notes of this website.

To students, please use a range of sources and cross-check them. Make sure in particular that the definitions you find are correct in the context of the case study.

To teachers, please continue to share your notes online, but be as careful as you can to make sure they’re correct and urge students to use a range of resources.

The Halting Problem

Is it possible to write a program A that takes another program B as input and which determines if B will halt or loop forever?

Well it turns out that an assumption that the answer is “yes” leads to a paradox and hence there is a proof by contradiction that the correct answer must be “no”.

The proof goes like this:

Assume program A can determine if program B will halt or loop forever.

Now I write a program C that calls program A as follows:

B = input_program
if A says B will halt then
   loop forever
else
   stop
end if

And I now feed program C to itself as input.

The result is that if C will halt, then it will loop forever, but if it will loop forever, then it will halt.

Disassembling C code to see the assembly language

We’ve been talking about assembly language in class recently and I’ve found a nice way of comparing source code with the assembly that the compile outputs. This is C, a compiled language.

int main() {
  divmod(26, 5);
}

int divmod (int dividend, int divisor) {
  int quotient = 0;
  while (dividend - divisor >= 0) {
    dividend = dividend - divisor;
    quotient = quotient + 1;
  }
}

The code divides 26 by 5 to give a quotient of 5 and remainder of 1, which is left stored in the dividend variable.

(This file was saved as divmod.c and then compiled using gcc, which is probably already installed on Mac computers. If you’re on Windows, you are advised to install the Community Edition of Microsoft Visual C++.)

Now, using a utility called objdump, which is preinstalled on my Linux laptop, I can now output the assembly code that was generated by the compiler. The output file of the compiler is called a.out, so that is the input to objdump. The flags tell objdump to include the source code intermixed with the assembly code, which is very handy for us!

The command to disassemble the compiled code is:

objdump -Sd --dwarf=info a.out

This provides a whole load of output, but in amongst it you can find the assembly code for the divmod function:

objdump output

Ordered Array Class

Arrays are static data structures, so their size is fixed when they are created. Array elements are contiguous in RAM. This means that if you want to slot a value into the middle of an array, you need to shift the other values first. Imagine trying to slot yourself in between two people in a crowded cinema.

2018-09-19_06-43

A good exercise is to code an OrderedArray class. This is a wrapper for an array of Integer object (use Integers not ints so that we can check for nulls) that has an insert method that slots new values in ascending order.

I would say that the complexity of this code is about as tough as it gets at SL. If you need some scaffolding, use the class template below. Otherwise just have a go at it yourself. In addition, code a constructor that allows you to set the size of the array.

class Main {
  // This main class is just for testing.
  public static void main(String[] args) {
    OrderedArray oArr = new OrderedArray(50);
    for (int i = 0; i < 30; i++) {
      java.util.Random r = new java.util.Random();
      oArr.insert(r.nextInt(100));
    }
    // You will need to code this method.
    // The numbers should be in order.
    oArr.print();
  }  
}

class OrderedArray {

  // What instance variables will you need?

  public OrderedArray(int size) {
  // Use the size parameter to set the size of the array.
  }

  void insert(int n) {
  // Insert the new number in the right place.
  // 1. Find out where it should go.
  // 2. Make room for it.
  }

  void print() {
  // Print the numbers to the console.
  }
}