/** @author Scott Marshall @author University of Glasgow, MSc IT Project 2001 @author Building an OnLine Course in Computing Fundamentals */ package ukacgla_KMap; import java.util.*; abstract public class Abstract_Minterm { /** Holds the String description of the location of all Cell objects added. The String description describes the 2D location of each cell added to the minterm, using row and column headers.*/ protected StringBuffer minterm; /** Records if Minterm is correct or not. Must be set as "correct" or "incorrect". A String is used for this information as a String is used to set the ActionCommand for each JCheckBox that will be linked to the Minterm. */ protected String correct; /** Holds all cell Objects. */ protected Vector cellVector; /** 2D integer array used to map Cells. */ protected int[][] dataMap; /** Number of rows in dataMap. */ protected int dataMapRows; /** Number of columns in dataMap. */ protected int dataMapCols; /** Used to combine Cell objects into a single simplified Minterm. Creates a new Vector to hold all cells. Creates a new StringBuffer to hold the strings of each cell. Records of this minTerm is correct or not. Builds a 2D Integer Array with all cells set to 0. This array will later be used in the simplify() method. */ public Abstract_Minterm(String b, int rows, int cols){ cellVector = new Vector(); minterm = new StringBuffer(); correct = b; dataMapRows = rows; dataMapCols = cols; dataMap = new int[dataMapRows][dataMapCols]; for (int i = 0; i < dataMapRows ; i++){ for (int j = 0; j < dataMapCols ; j++){ dataMap[i][j] = 0; } } } /** Returns String recording if Minterm is correct or false. */ public String getCorrect() { return correct; } /** Returns Minterm as a string. */ public String getMinterm() { return minterm.toString(); } /** Adds Cell to Vector. Add String of Cell object to Minterm StringBuffer. Adds a + to separate Cell strings. Sets the dataMap to 1 to indicate a cell occupies this space in the map. */ public void add(Abstract_Cell c){ cellVector.add(c); minterm.append(c.getCell()); minterm.append("+"); dataMap[c.getxCoord()][c.getyCoord()] = 1; } /** Concrete child classes will read dataMap[][] for specific sequences. If specified sequence is met, append chars to answer, and reset data in table Finally, make this instance of minterm a copy of answer. */ abstract public void simplify(); /** Used to trim minterms of any excess '+'s created during building. */ public void trim() { int length = minterm.length(); if (minterm.charAt(length-1)=='+') minterm.deleteCharAt(length-1); } }