Chapter 7. The 'Random arcs' application

Table of Contents

Step 1: Create a new application
Step 2: Creating objects
Step 3: Unit testing
Advantages (so far)
Step 4: Making data more reliable and secure
Step 5: Object conversions and error handling
Step 6: File input/output
Step 7: Creating the 'random arcs' picture
Step 8: Testing the application

We are now going to write an application that creates a picture based on random data provided by people. The picture will be composed of adjacent 90 degrees arcs with different radii and colors. Here is an example of the final result:

Figure 7.1. Obix programming language random arcs tutorial example

Obix programming language random arcs tutorial example

The arcs' radii will be based on data provided by users of the application. A single user input for one arc is called a contribution and is composed of:

The application will be able to collect contributions directly submitted by users (e.g. via a web site) and/or by other applications (e.g. via a HTTP request). All contributions will be saved in a JSON text file.

The arcs' colors will be defined by a random generator.

The final picture will be created in the Scalable Vector Graphics (SVG) format and stored in a file.

[Note]Note
This application clearly doesn't belong to the category 'life saving applications'. Despite this fact we will nevertheless write reliable code. User input data can be invalid or malicious, and resources like files can fail at runtime. Therefore, invalid data protection and resource error handling will play a very important role in the following chapters. The objective is to see how to write professional, reliable applications.

To develop this application you will do the following:

  1. Create a new application
  2. Write code to create contribution objects
  3. Write unit tests (to detect bugs)
  4. Make data more reliable and secure (!)
  5. Convert objects to (and re-create them from) JSON
  6. Use files to store/restore data
  7. Create the 'random arcs' picture and save it in a SVG file
  8. Run the application with test data (and hopefully enjoy beautil drawings)
[Note]Note
The full project with source code is included in the Obix download. It is located in subdirectory projects/pr_ex_21_random_arcs/.

Step 1: Create a new application

To create the 'random arcs' application proceed as follows:

  • Open a system console (a text terminal in Linux, or a command line window in Windows).

  • Go to the root directory of your Obix installation.

  • Create a new project named random_arcs by entering the following command:

    on Linux type:
    ./obix.sh create_project project_id:random_arcs kind:java
    
    on Windows type:
    obix create_project project_id:random_arcs kind:java

    Obix creates a directory named pr_random_arcs in subdirectory projects of your Obix installation (e.g. obix-0.7.5/projects/pr_random_arcs)

If you need more information please look at the README.TXT file in the project's root directory or refer to the previous Chapter 4, How to develop a standard PC application?.