Loyola College 2006-07 High School Programming Contest


Loyola College > Department of Computer Science > Dr. James Glenn > HS Programming Contest > Coding Guidelines

Problems are designed so that solutions can be written using concepts from the AP Java Subset. Other concepts may be useful and teams are welcome to employ them. Because of declining use, C++ is no longer supported.

Some problems involve writing static methods that, given an object and other parameters, query the object and produce some output or a return value. In such cases, we will provide the skeleton of the class in which the methods should be added.

Other problems involve adding methods to existing classes. When those methods are mutators (methods that change the state of the object they are invoked on), helper methods will be provided so that teams do not have to work directly with instance variables.

Input and Output

Input will by handled by the test drivers or by constructors and methods in provided classes. For example, if input must be read from a file, there will be either a constructor that takes a filename as a parameter, or a constructor that takes a Scanner object as a parameter; the Scanner object will be created by the provided sample test driver. Once the data has been read into an object, teams can query the object via its methods to see what the input was. As an alternative to creating test input files, there will also be methods that allow teams to set up objects as they wish using methods.

For example, if a problem involves working with a Tic-Tac-Toe board, we may provide a constructor so that a board can be initialized with

TicTacToeBoard b = new TicTacToeBoard("board.txt")
where board.txt would be the name of a file containing a straightforward representation of the board. We would also provide constructors and methods to allow something like
TicTacToeBoard b = new TicTacToeBoard();
b.mark(0, 0, 'X');
b.mark(1, 1, 'O');
so testers can create an empty board and then place X's and O's as they wish.

Output, when handled by team-written code [clarified 1/30/2007], will consist of System.out.print or System.out.println statements. When sample output is given in a problem description, it should be assumed, unless it is otherwise stated, that there are no blank lines in the output, and that there are no extra whitespace characters between the last non-whitespace character and the newline character. For example, if the sample output is

Programming Contest
2007
then acceptable code to produce that output would be
System.out.println("Programming Contest");
System.out.println("2007");
but not
System.out.println("Programming Contest  "); // note the extra spaces
System.out.println("2007");
and not
System.out.println("Programming Contest");
System.out.println("2007");
System.out.println(); // there shouldn't be an extra blank line

Collections

Some provided code will use classes from the Java Collections Framework. In such cases, parameterized classes will not be used as they are not part of the AP Java subset. For example, Java 1.5 allows a method such as

public class StudentList
{ 
  ...

  public List< String > getNames() 
  {
    ...
  }

  ...
}
Without parameterized classes, the return type of getNames would simply be List, and we would have to cast the Objects we get from the List to Strings: instead of
StudentList students = new StudentList();
List< String > l = students.getNames();
if (l.size() > 0 && l.get(0).length() > 0)
{
  char initial = l.get(0).charAt(0);
  System.out.println("First initial of first name: " + initial);
}
we would write
StudentList students = new StudentList();
List l = students.getNames();
if (l.size() > 0 && ((String)(l.get(0))).length() > 0)
{
  char initial = ((String)(l.get(0))).charAt(0);
  System.out.println("First initial of first name: " + initial);
}
which will work but will result in the following compiler warnings
Note: StudentList.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
which can be safely ignored for the purposes of the contest.

Please note that the version of Eclipse we are using for the contest does not allow Java 1.5 syntax. Teams using jGRASP may use Java 1.5 parameterized classes in their own code.

Furthermore, wherever collections are used, alternate means of accessing the items in the collection will be provided. For example, we may provide methods to count the number of names, and retrieve the names by index, so that

List l = students.getNames();
Iterator i = l.iterator();
while (i.hasNext())
  System.out.println(i.next());
and
for (int i = 0; i < students.countNames(); i++)
  System.out.println(students.getName(i));
would behave identically.
Last updated Sat Feb 2, 2007

Valid HTML 4.01 Transitional