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:

Pagination and Sorting using Spring Data JPA
Java Program to Implement Double Order Traversal of a Binary Tree
Composition, Aggregation, and Association in Java
Marker Interface trong Java
Server-Sent Events in Spring
Java Program to Implement Naor-Reingold Pseudo Random Function
Java Program to Solve the 0-1 Knapsack Problem
Java Program to Implement the Hungarian Algorithm for Bipartite Matching
Tips for dealing with HTTP-related problems
Quick Guide to Spring Controllers
Java – Rename or Move a File
Java Program to Perform Deletion in a BST
Giới thiệu Google Guice – Dependency injection (DI) framework
Java Program to Implement the Checksum Method for Small String Messages and Detect
REST Web service: Upload và Download file với Jersey 2.x
Java Program to Use Dynamic Programming to Solve Approximate String Matching
Java Program to Implement Gaussian Elimination Algorithm
Java Program to Perform Optimal Paranthesization Using Dynamic Programming
Java Program to Perform integer Partition for a Specific Case
Java Program to Emulate N Dice Roller
Java Program to Test Using DFS Whether a Directed Graph is Strongly Connected or Not
Java Program to Implement Sorted Circular Doubly Linked List
Convert char to String in Java
Java Program to find the maximum subarray sum O(n^2) time(naive method)
Spring Boot - CORS Support
Spring MVC Tutorial
Java Program to Implement Wagner and Fisher Algorithm for online String Matching
Cơ chế Upcasting và Downcasting trong java
Java Program to Implement Stack
How to Break from Java Stream forEach
Guide to the Volatile Keyword in Java
Spring Boot - Bootstrapping