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.

  1. import java.util.HashMap;
  2. import java.util.Map;
  3.  
  4. public class ControlTable
  5. {
  6.     private Map<String,Integer> controlTable;
  7.  
  8.     public ControlTable()
  9.     {
  10.         controlTable = new HashMap<String,Integer>(); 
  11.         populateTable();
  12.     }
  13.  
  14.     public int[] controlTable(int[] asciiCodes)
  15.     {
  16.         int[] index = new int[asciiCodes.length];
  17.         for (int val = 0; val < asciiCodes.length; val++)
  18.         {
  19.             index[val] = controlTable.get(Integer.toHexString(asciiCodes[val]));
  20.         }
  21.         return index;
  22.     }
  23.  
  24.     private void populateTable()
  25.     {
  26.         controlTable.put(Integer.toHexString(65), 01);
  27.         controlTable.put(Integer.toHexString(68), 04);
  28.         controlTable.put(Integer.toHexString(77), 03);
  29.         controlTable.put(Integer.toHexString(83), 02);
  30.     }
  31.  
  32.     public static void main (String...arg)
  33.     {
  34.         int[] asciiCodes = new int[4];
  35.         int[] tableOutput;
  36.         asciiCodes [0] = (int) 'A';
  37.         asciiCodes [1] = (int) 'D';
  38.         asciiCodes [2] = (int) 'M';
  39.         asciiCodes [3] = (int) 'S';
  40.  
  41.         ControlTable controlTable = new ControlTable();
  42.         tableOutput = controlTable.controlTable(asciiCodes);
  43.  
  44.         System.out.println("Input values ");
  45.         System.out.print("( ");
  46.         for (int i = 0; i < asciiCodes.length; i++)
  47.         {
  48.             System.out.print((char)asciiCodes[i] + " ");	
  49.         }
  50.         System.out.print(")\n");
  51.  
  52.         System.out.println("New Index from Control table");
  53.         System.out.print("( ");
  54.         for (int i = 0; i < tableOutput.length; i++)
  55.         {
  56.             System.out.print(tableOutput[i] + " ");
  57.         }
  58.         System.out.print(")");
  59.     } 	
  60. }


$javac ControlTable.java
$java ControlTable
Input values 
( A D M S )
New Index from control table
( 1 4 3 2 )

Sanfoundry Global Education & Learning Series – 1000 Java Programs.

advertisement
advertisement
If you wish to look at all Java Programming examples, go to Java Programs.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.