Programming Taskbook


E-mail:

Password:

User registration   Restore password

Russian

SFedU

1100 training tasks on programming

©  M. E. Abramyan (Southern Federal University), 1998–2018

 

Examples | Java | PT4 classes

PrevNext


Additional classes, their methods and properties

Classes described in this section are defined in PT.java file. Any template project created for task solving on Java imports this file.

The PT class: common description


public class PT
{
// Method initializing a task:
    public static void task(String name)
// Methods providing initial data input:
    public static boolean getBoolean()
    public static int getInt()
    public static double getDouble()
    public static char getChar()
    public static String getString()
    public static Node getNode()
// Method providing results output:
    public static void put(Object... a)
// Methods providing debug output:
    public static void show(Object a)
    public static void showLine(Object a)
    public static void showLine()
    public static void hideTask()
}

The PT class provides tools for task initialization and data input-output. A solution of task should be developed in solve function, which must contain calls of methods of the PT class.

Some features of methods of the PT class are described below.

Task initialization, data input-output

The task method initializes a task named name. It must be called at the beginning of the solve function that contains task solution. If the solve function does not contain the task method call then the program output the error message "The task function with a task name is not called".

A task name must contain a name of a task group and an order number (for example, "Begin3"). If the group name is invalid then the program output the error message "Invalid task group". If the task number is invalid then the program output the error message with information about the range of the available task numbers for this group. The symbol "?" placed after the task name (for example, "Begin3?") means that the program will be run in the demo mode.

The task function may be also used for creating and displaying an html-page containing a description of a task or a task group. In this case the name of the required task or the task group ended by the "#" symbol must be used for the name parameter, for example, "Begin3#" or "Begin#".

Starting from the version 4.13, the Programming Taskbook provides a program testing on several sets of input data during a single running of the program. You should place the sumbol "!" after the task name (for example, "Begin3!") in order to switch off this new feature.

All subsequent calls of the task function are ignored with the following exception: if several calls are used for creation of an html-page containing a description of various tasks or task groups then all these calls will be taken into account.

Starting from the version 4.12, the name parameter may include the "_en" or "_ru" suffix that determines the interface language (English or Russian respectively) for Programming Taskbook window and the task itself. The "?", "#", and "!" symbols should be placed before the suffix, for example, "Begin3#_en". If several calls of the task function are used (for creation of an html-page) then only the suffix of the first call will be taken into account. If the suffix is absent then the default language is applied (the default language may be changed by means of a pop-up menu of the PT4Load tool).

The get methods must be used to input initial data values in the program. They must be called after the task method, otherwise the program output the error message "The task function with a task name is not called at the beginning of the program".

Each input method must correspond to the type of data item, otherwise the program output the following message: "Invalid type is used for an input data item" . For example, this message will be output if getInt method will be called for input a string.

In the case of input of more data than the task requires, the program output the error message "An attempt to input superfluous data". In the case of input of less data than the task requires, the program output the error message "Some required data are not input".

The put method must be used to output results on the screen and compare obtained results with control data (i.e., correct results). It must be called after the task method, otherwise the program output the error message "The task function with a task name is not called at the beginning of the program".

The put method may be used for output data of any admissible type: boolean, int, double, char, String, and Node. Due to a parameter type Object... it is possible to use any number of parameters in the put method. If one of parameters is of invalid type then the program raises the IllegalArgumentException exception with the error message "The put method has an argument of invalid type". A parameter type must correspond to the type of output data item, otherwise the program output the error message "Invalid type is used for an output data item".

In the case of output of more data than the task requires, the program output the error message "An attempt to output superfluous data". In the case of output of less data than the task requires, the program output the error message "Some data are not output".

Output debug info

The show, showLine, and hideTask methods are intended to output some debug data into the debug panel located below the task panels of the Programming Taskbook window.

The show method shows a data item of any type in the debug panel. The parameter of the method is automatically converted to its string representation.

The string parameter may contain explicit line-breaks as follows: '\r' (carriage return), '\n' (new line) or their combination "\r\n".

Using the concatenation + you may output numeric data jointly with the preceding comment as follows:

show("a = " + a);

Here a is a numeric variable.

The showLine method additionally breaks the current screen line.

The hideTask method hides all sections of the Programming Taskbook window with the exception of the debug section (and therefore increases the debug panel height). If the debug panel contains no data then the call of the hideTask method is ignored. All subsequent calls of this method are ignored too.

After displaying the Programming Taskbook window you can hide/restore task sections of this window by means of the space key or the command of the pop-up menu.

The Node class


public static class Node
{
// Constructors:
    public Node()
    public Node(int data)
    public Node(int data, Node next)
    public Node(int data, Node next, Node prev)
    public Node(Node left, Node right, int data)
    public Node(Node left, Node right, int data, Node parent)
// Accessors to properties:
    public int getData()
    public void setData(int value)
    public Node getNext()
    public void setNext(Node value)
    public Node getPrev()
    public void setPrev(Node value)
    public Node getLeft()
    public void setLeft(Node value)
    public Node getRight()
    public void setRight(Node value)
    public Node getParent()
    public void setParent(Node value)
// Method that releases resources used by the Node object:
    public void dispose()
}

The Node class is an internal class of the PT class and is used in the Dynamic and Tree group tasks. In the introductory tasks of the Dynamic group (Dynamic1–Dynamic2) and in the tasks devoted to stacks and queues (Dynamic3–Dynamic28) the Data and Next properties of the Node class are used. In the tasks devoted to lists (Dynamic29–Dynamic80) all properties (Data, Next, Prev) of Node class are used. In the most tasks devoted to binary trees the Data, Left, and Right properties of the Node class are used. The Parent property is used in the tasks devoted to doubly linked binary trees (Tree48–Tree56 and Tree70–Tree71).

Note that the dispose method should be called for any Node object, except objects that are output data for this task. If the Dispose method is not called for required objects then the program output the error message.


PrevNext

 

  Рейтинг@Mail.ru

Designed by
M. E. Abramyan and V. N. Braguilevsky

Last revised:
06.05.2018