Mastery Factor: ADTs

I read something that Dave Mulkey wrote in this forum in 2009 on the subject of ADTs as a mastery factor:

As I said above, my students never try to get 4 marks, and usually not 3.  They just implement the most normal features with normal error checking and that’s sufficient for 2 marks.  If they really need 4 marks (say there are no files in the application), it’s easier to implement 2 different ADTs and get 2 marks for each.

Huh?! Can you do that?! It would be great news if so, but I think it needs to be made much clearer in the guide.

Justin

+++++++++++++++++++++++++++++++++++++++++++

Hi Jason,

That is certainly a good question.  I’d agree this is not thoroughly explained in the Guide.

The May 2006 Subect Report says:

“Candidates may gain some credit for all ADTs which have been properly documented, implemented and demonstrated to work via hard copy. Four such ADTs which all work only partially may gain the full 4 marks (although it does seem a hard way to go about it).”

I recommend reading the Subject Reports – they contain lots of clarifications.  In case you have a real life and don’t want to read all of them, I recommend May 2006 and May 2009 as being particularly helpful.  May 2009 has a nice chart about Mastery Factors, which is short, clear and useful.

My students don’t create 2 ADT’s very often, but I have given “partial marks” to some of my students for multiple ADT’s, as well as giving them as a moderator.  I’ve never heard any complaints about this.  Still, what I’m saying is not “official”.  If you want an official answer, you can have your IB Coordinator send an official query to the IBO and you will receive an official and binding answer from the office.

Awarding Mastery marks is a subjective issue, with only broad guidelines to help standardize things.  The best thing you can do for your students is to clearly explain your thinking, on paper, and include this with the samples that go to the moderator.  It’s a lot easier for a moderator to support your marks if they understand why they were awarded, rather than trying to guess what the teacher was thinking.  It’s not necessary to explain ALL the marks – e.g at SL if there are numerous IF..ELSE.. constructs throughout the program, a simple list of page numbers/line numbers of a few of them is sufficient.  But the ADT marks are quite variable across schools, so a brief explanation from the teacher is very helpful.  Also, the students are expected to “document” (explain or discuss or justify) their Mastery aspects.  In my experience, the students don’t tend to write very clear (or even correct) explanations, so the teacher’s comments are a big help.  If you read those Subject Reports, you’ll see the word “justify” used repeatedly.  I think that sounds a bit like arguing a case in a court of law.  I prefer the word “explain”.  But the Subject Reports are written by the Senior Moderator  and/or Chief Examiner (as far as I know), so I would take those suggestions seriously.

From the May 2006 Subject Report:

“Perhaps the biggest issue with mastery aspects is the frequent lack of documentation or inaccuracies in documentation. These cover several aspects such as administrative errors, lack of hard copy output and lack of discussion of the need of the solution for certain mastery aspects.”

The key point there is “the need of the solution for certain mastery aspects”.  In this case, I think the statement in the 2010 Guide (p 65) is actually clearer:

”  “Non-trivial” means that the programmer must demonstrate that the program benefits from the use of the [mastery] aspect.

Where one aspect includes others, all are credited (always provided that the use is non-trivial, well documented and appropriate).”

I like the idea “benefits from”.  Most importantly, the program must actually USE (execute) the code that was written.  I’ve seen a number of dossiers where a perfectly functionaly Linked-List has been coded, but is never actually executed.  Even more commonly, methods or ADT’s are coded and then executed once, but for no particular reason.  Hence the application did not actually “benefit” from using that code.

The worst error (sorry, I’m getting carried away but I must say this) that I’ve seen repeatedly is incorrect use of recursion.  Students know they can get a mastery mark for using recursion, so they code a “recursive” method by having it call itself instead of using a loop.  Unfortunately, in several cases the recursion was coded incorrectly and never terminated, and the students turned in dossiers with no sample output because the program locked up in an infinite loop.  Clearly, those programs did not “benefit” from the use of recursion.

Perhaps that was “too much information”.  Hope it helps anyway.

Dave Mulkey

Mastery Factor: Parsing a text file

Parsing a text file or other data stream

Using the built-in wrapper classes such as Integer and Double with their methods parseInt(String) and parseDouble(String) is considered a trivial use. An input data stream, such as from a file, the keyboard or a network, which consists of character bytes representing text, should be split into separate components in some way.  The use of String.split() or java.util.StringTokenizer is acceptable.  The components must then be recognised as belonging to a particular set, each with a particular processing requirement.  Taking lines from a text file in csv or similar formats and creating record-style object instances is an acceptable use.  In this type conversion using Integer.parseInt() etc is fine.  The formats and the process of interpretation must be discussed in the data structures and algorithms of stage B.

https://retrosnob.files.wordpress.com/2011/11/subject-report-may-2006.pdf

Thanks Blanca.

A few points about the recursion mastery factor

The question of the recursion mastery factor has cropped up a few times on the IBO computer science forum and if you are considering incorporating it into your dossier you need to bear these points in mind:

  • Don’t include recursion unless it is appropriate. It should be used for quicksort, or for binary tree traversal, and that is about it. If you have any other use in mind, please ask me first.
  • Don’t use recursion to implement a while loop, eg to keep asking the user for input until they type ‘x’. This is inappropriate and can actually cause a stack overflow.
  • Don’t use recursion where an iterative method would be easier. The whole point of recursion is that it can provide very elegant solutions to what would otherwise be quite complicated procedures. If you don’t believe me, try traversing a binary tree iteratively.
  • Even if you do use it for sorting, make sure that ‘sortability’ is a success criterion. Otherwise it can look like you’ve only included a sort to gain the mastery factor, and that is not really the point.

Java File IO

There are lots of ways of writing to files in Java but the IB seem to recommend BufferedReader for input and PrintWriter for output. Here is an example of how to use them.

The program provides a general purpose class to read from an input file called in.txt and write to an output file called out.txt. The main routine uses this class to read lines from a comma-delimited file and write them out with the delimiter changed to a # character. I chose this example because it shows you not only basic file input/output, but it also shows you how to you can use a delimiter to structure your file.

The output file will be created if it doesn’t already exist but you must create an input file called in.txt and save it at the root c: before you run this code. Sample input file contents plus Java code is provided below.

Presidency,President,Took office,Left office,Party,Home State
1,George Washington,30/04/1789,4/03/1797,Independent,Virginia
2,John Adams,4/03/1797,4/03/1801,Federalist,Massachusetts
3,Thomas Jefferson,4/03/1801,4/03/1809,Democratic-Republican,Virginia
4,James Madison,4/03/1809,4/03/1817,Democratic-Republican,Virginia
5,James Monroe,4/03/1817,4/03/1825,Democratic-Republican,Virginia
6,John Quincy Adams,4/03/1825,4/03/1829,Democratic-Republican/National Republican,Massachusetts
7,Andrew Jackson,4/03/1829,4/03/1837,Democratic,Tennessee
8,Martin Van Buren,4/03/1837,4/03/1841,Democratic,New York
9,William Henry Harrison,4/03/1841,4/04/1841,Whig,Ohio
10,John Tyler,4/04/1841,4/03/1845,Whig,Virginia
11,James K. Polk,4/03/1845,4/03/1849,Democratic,Tennessee
12,Zachary Taylor,4/03/1849,9/07/1850,Whig,Louisiana
13,Millard Fillmore,9/07/1850,4/03/1853,Whig,New York
14,Franklin Pierce,4/03/1853,4/03/1857,Democratic,New Hampshire
15,James Buchanan,4/03/1857,4/03/1861,Democratic,Pennsylvania
16,Abraham Lincoln,4/03/1861,15/04/1865,Republican/National Union,Illinois
17,Andrew Johnson,15/04/1865,4/03/1869,Democratic/National Union,Tennessee
18,Ulysses S. Grant,4/03/1869,4/03/1877,Republican,Ohio
19,Rutherford B. Hayes,4/03/1877,4/03/1881,Republican,Ohio
20,James A. Garfield,4/03/1881,19/09/1881,Republican,Ohio
21,Chester A. Arthur,19/09/1881,4/03/1885,Republican,New York
22,Grover Cleveland,4/03/1885,4/03/1889,Democratic,New York
23,Benjamin Harrison,4/03/1889,4/03/1893,Republican,Indiana
24,Grover Cleveland (2nd term),4/03/1893,4/03/1897,Democratic,New York
25,William McKinley,4/03/1897,14/9/1901,Republican,Ohio
26,Theodore Roosevelt,14/9/1901,04/03/09,Republican,New York
27,William Howard Taft,04/03/09,04/03/13,Republican,Ohio
28,Woodrow Wilson,04/03/13,04/03/21,Democratic,New Jersey
29,Warren G. Harding,04/03/21,02/08/23,Republican,Ohio
30,Calvin Coolidge,02/08/23,04/03/29,Republican,Massachusetts
31,Herbert Hoover,04/03/29,04/03/33,Republican,Iowa
32,Franklin D. Roosevelt,04/03/33,12/04/45,Democratic,New York
33,Harry S. Truman,12/04/45,20/01/1953,Democratic,Missouri
34,Dwight D. Eisenhower,20/01/1953,20/01/1961,Republican,Texas
35,John F. Kennedy,20/01/1961,22/11/1963,Democratic,Massachusetts
36,Lyndon B. Johnson,22/11/1963,20/1/1969,Democratic,Texas
37,Richard Nixon,20/1/1969,09/08/74,Republican,California
38,Gerald Ford,09/08/74,20/01/1977,Republican,Michigan
39,Jimmy Carter,20/01/1977,20/01/1981,Democratic,Georgia
40,Ronald Reagan,20/01/1981,20/01/1989,Republican,California
41,George H. W. Bush,20/01/1989,20/01/1993,Republican,Texas
42,Bill Clinton,20/01/1993,20/01/2001,Democratic,Arkansas
43,George W. Bush,20/01/2001,20/01/2009,Republican,Texas
44,Barack Obama,20/01/2009,Incumbent,Democratic,Illinois

package fileiodemo;

import java.io.*;
import java.util.*;

/**
 * @author robertsonj
 */
public class FileIODemo {

    public static void main(String[] args) {       
        final String OLD_DELIMITER = ",";
        final String NEW_DELIMITER = "#";
        FileIO io = new FileIO();
        String sInput;
        String[] sSplit;
        
        // get the first line
        sInput = io.input(); 
        while (sInput != null){
            // split the line up into an array of strings on the basis 
            // of the old delimiter
            sSplit = sInput.split(OLD_DELIMITER);
            
            // loop through the array, writing each string to the output
            // file and using the new delimiter
            for(int i = 0; i<sSplit.length; i++){
                if (i>0) io.output(NEW_DELIMITER, false);
                io.output(sSplit[i], false);
            }
            // add a new line character
            io.output("", true);
            // get the next line
            sInput = io.input();
        }
        io.closeAll();
    }
}

class FileIO {

    final String OUTPUT_FILENAME = "c:\\out.txt";
    final String INPUT_FILENAME = "c:\\in.txt";
    BufferedReader reader;
    PrintWriter writer;

    FileIO() {
        try {
            reader = new BufferedReader(new FileReader(INPUT_FILENAME));
            writer = new PrintWriter(new FileWriter(OUTPUT_FILENAME));
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }

    void output(String s, boolean newLine) {
        if (newLine) {
            writer.println(s);
        }
        else {
            writer.print(s);            
        }
    }

    String input() {
        String s = "";
        try {
            s = reader.readLine();
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return s;
    }

    void closeAll() {
        try {
            reader.close();
            writer.close();
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
}

Bad IB questions 2

Here’s another one.

Question:
Outline how a run-time error could occur in a computer program (2 marks)

Mark Scheme Answer:
Attempt to divide by zero (1 mark); error occurs because this is an illegal operation for the compiler (1 mark)

Truth:
Firstly, divide by zero is one of hundreds of possible run-time errors. Other examples are null pointer exceptions, array out of bounds, type mismatch, overflow, out of memory, etc. Secondly, by its very definition a run-time error has nothing to do with the compiler. The compiler has long since left the equation. The compiler can only generate compile-time errors, which are often syntax errors, like “else with if” or “expected ;”, or can be structural or semantic problems like “method not found”, “cannot return a value from method of type void”, or “not a statement”.