Java Program to Implement Control Table

This Java program is to implement control table. Control tables are tables that control the control flow or play a major part in program control. There are no rigid rules about the structure or content of a control table—its qualifying attribute is its ability to direct control flow in some way through “execution” by a processor or interpreter. The design of such tables is sometimes referred to as table-driven design.
In perhaps its simplest implementation, a control table may sometimes be a one-dimensional table for directly translating a raw data value to a corresponding subroutine offset, index or pointer using the raw data value either directly as the index to the array, or by performing some basic arithmetic on the data beforehand.

Here is the source code of the Java program to implement control table. The Java program is successfully compiled and run on a Linux system. The program output is also shown below.

import java.util.HashMap;
import java.util.Map;
 
public class ControlTable
{
    private Map<String,Integer> controlTable;
 
    public ControlTable()
    {
        controlTable = new HashMap<String,Integer>(); 
        populateTable();
    }
 
    public int[] controlTable(int[] asciiCodes)
    {
        int[] index = new int[asciiCodes.length];
        for (int val = 0; val < asciiCodes.length; val++)
        {
            index[val] = controlTable.get(Integer.toHexString(asciiCodes[val]));
        }
        return index;
    }
 
    private void populateTable()
    {
        controlTable.put(Integer.toHexString(65), 01);
        controlTable.put(Integer.toHexString(68), 04);
        controlTable.put(Integer.toHexString(77), 03);
        controlTable.put(Integer.toHexString(83), 02);
    }
 
    public static void main (String...arg)
    {
        int[] asciiCodes = new int[4];
        int[] tableOutput;
        asciiCodes [0] = (int) 'A';
        asciiCodes [1] = (int) 'D';
        asciiCodes [2] = (int) 'M';
        asciiCodes [3] = (int) 'S';
 
        ControlTable controlTable = new ControlTable();
        tableOutput = controlTable.controlTable(asciiCodes);
 
        System.out.println("Input values ");
        System.out.print("( ");
        for (int i = 0; i < asciiCodes.length; i++)
        {
            System.out.print((char)asciiCodes[i] + " ");	
        }
        System.out.print(")\n");
 
        System.out.println("New Index from Control table");
        System.out.print("( ");
        for (int i = 0; i < tableOutput.length; i++)
        {
            System.out.print(tableOutput[i] + " ");
        }
        System.out.print(")");
    } 	
}
$javac ControlTable.java
$java ControlTable
Input values 
( A D M S )
New Index from control table
( 1 4 3 2 )

Related posts:

Java Program to Solve any Linear Equation in One Variable
Java Program to Find Number of Articulation points in a Graph
Guide to @JsonFormat in Jackson
Java Program to Implement Disjoint Sets
Java Program to Implement LinkedHashMap API
Tổng quan về ngôn ngữ lập trình java
Java String Conversions
Derived Query Methods in Spring Data JPA Repositories
XML Serialization and Deserialization with Jackson
Login For a Spring Web App – Error Handling and Localization
Java Program to Represent Graph Using Adjacency Matrix
Java Byte Array to InputStream
Java Program to Search for an Element in a Binary Search Tree
Converting String to Stream of chars
Iterating over Enum Values in Java
So sánh ArrayList và LinkedList trong Java
HttpClient 4 Cookbook
Practical Java Examples of the Big O Notation
REST Web service: Tạo ứng dụng Java RESTful Client với Jersey Client 2.x
Split a String in Java
Một số nguyên tắc, định luật trong lập trình
Hướng dẫn Java Design Pattern – Decorator
Comparing getPath(), getAbsolutePath(), and getCanonicalPath() in Java
Java Program to Implement VList
Java Program to Perform Preorder Recursive Traversal of a Given Binary Tree
Từ khóa static và final trong java
So sánh HashSet, LinkedHashSet và TreeSet trong Java
Java Program to Find the Peak Element of an Array O(n) time (Naive Method)
Java Program to Evaluate an Expression using Stacks
Using a Spring Cloud App Starter
Java Program to Find k Numbers Closest to Median of S, Where S is a Set of n Numbers
Feign – Tạo ứng dụng Java RESTful Client