Assig 4
Assig 4
Assig 4
* Joseph Cortez
* Lyndsay Hackett
* Mokhlis Awad
* Ahdia Fuller
* Assig 4 Class: An Interface and set of classes to print out barcodes and secret messages.
*/
String[] sImageIn =
" ",
" ",
" ",
" * * * * * * * * * * * * * * * * * * * * * ",
" * * ",
" * ** * * ** * * * * * ",
" ",
" ",
" "
};
String[] sImageIn_2 =
" ",
" ",
"* * * * * * * * * * * * * * * * * * * ",
"* * ",
"*** * * * ** * ** ",
"**** * * * * ** ** * ** * * * ",
"************************************** ",
" ",
" ",
" ",
" "
};
// creates BarcodeImage object to hold first barcode and sends to DataMatrix for decoding
dm.translateImageToText();
dm.displayTextToConsole();
dm.displayImageToConsole();
bc = new BarcodeImage(sImageIn_2);
dm.scan(bc);
dm.translateImageToText();
dm.displayTextToConsole();
dm.displayImageToConsole();
// Custom message
dm.generateImageFromText();
dm.displayTextToConsole();
dm.displayImageToConsole();
interface BarcodeIO
{
/**
* Accepts some image, represented as a BarcodeImage object to be described below, and stores a
copy of this image
* @return boolean
*/
/**
* @return boolean
*/
/**
* Looks at the internal text stored in the implementing class and produces a companion
BarcodeImage, internally
* (or an image in whatever format the implementing class uses). After this is called, we expect the
implementing
* object to contain a fully-defined image and text that are in agreement with each other.
* @return boolean
*/
/**
* After this is called, we expect the implementing object to contain a fully defined image and text that
are in
* @return boolean
*/
/**
*/
/**
*/
/*
* BarcodeImage Class
*/
/* Default Constructor
*/
public BarcodeImage()
image_data[i][k] = false;
/* Non-Default Constructor
*/
this();
if (checkSize(str_data) == true)
if (str_data[i].charAt(k) == '*')
else
// checkSize failed
else
/*
* Accessor - getPixel
* Validates the values for row and column to ensure they are within
*/
try
return image_data[row][col];
} catch (IndexOutOfBoundsException e)
return false;
/*
* Mutator - setPixel
* Validates the values for row and column to ensure they are within
*/
try
{
image_data[row][col] = value;
return true;
} catch (IndexOutOfBoundsException e)
return false;
/*
* clone
*/
try
cloned.image_data = image_data.clone();
return cloned;
catch (CloneNotSupportedException e)
return null;
/* checkSize
* A private util used to validate whether the string data passed into the BarcodeImage
* non-default constructor is within the bounds of MAX_HEIGHT and MAX_WIDTH, is not zero or null.
* Returns false if the lenght of the data is equal to, or less than zero, or greater than
* MAX_HEIGHT or MAX_WIDTH.
*/
if (data.length <= 0) {
return false;
return false;
return false;
if (data == null) {
return false;
return true;
//Phase 3
/*
* DataMatrix Class
* scans a copy of image and displays image and translated text to console
*/
// Fields
public DataMatrix()
text = "";
actualWidth = 0;
actualHeight = 0;
// Constructor
scan(image);
text = "";
// Constructor
public DataMatrix(String text)
readText(text);
actualWidth = 0;
actualHeight = 0;
/**
* Accepts some image, represented as a BarcodeImage object to be described below, and stores a
copy of this image
* @return boolean
*/
this.image = bc.clone();
cleanImage();
actualWidth = computeSignalWidth();
actualHeight = computeSignalHeight();
return true;
moveImageToLowerLeft();
}
// Method that moves the image to the lower left corner
shiftImageLeft(horizontalScanner());
shiftImageDown(verticalScanner());
if(offset == BarcodeImage.MAX_HEIGHT - 1)
return;
if(offset == 0)
{
return;
if(image.getPixel(row, col))
return col;
return BarcodeImage.MAX_WIDTH - 1;
if(image.getPixel(row, col))
return row;
return BarcodeImage.MAX_HEIGHT - 1;
return actualWidth;
return actualHeight;
if(!image.getPixel(BarcodeImage.MAX_HEIGHT - 1, i))
return i;
return BarcodeImage.MAX_WIDTH - 1;
if(image.getPixel(i, 0))
return BarcodeImage.MAX_HEIGHT - i;
return BarcodeImage.MAX_HEIGHT - 1;
return true;
return false;
str_data[i] = ""+BLACK_CHAR;
ascii -= yval;
str_data[row] += BLACK_CHAR;
else
{
str_data[row] += WHITE_CHAR;
if (i % 2 == 0)
str_data[0] += WHITE_CHAR;
else
str_data[0] += BLACK_CHAR;
str_data[str_data.length-1] += BLACK_CHAR;
if (i % 2 == 0)
str_data[i] += WHITE_CHAR;
else
str_data[i] += BLACK_CHAR;
cleanImage();
return true;
int ascii = 0;
if (image.getPixel(row, col))
else
ascii += 0;
text = translation;
return true;
/**
*/
System.out.println(text);
}
/**
*/
onlyBarcode += "-";
onlyBarcode += "\n";
onlyBarcode += "|";
onlyBarcode += "|\n";
onlyBarcode += "-";
System.out.println(onlyBarcode);
}
}
/*******************TEST RUN***********************************************
-------------------------------------------
|* * * * * * * * * * * * * * * * * * * * *|
|* *|
|* * ******************************|
|* ** * * ** * * * * * |
|* * * ***** * * * * ** ***|
|* ** * *** ** ** * ** *** * |
|***** *** * * * ** ** ** * * * |
|*****************************************|
-------------------------------------------
----------------------------------------
|* * * * * * * * * * * * * * * * * * * |
|* *|
|** * * * *** ** |
|*** * * * ** * **|
|* ** * * * * * * ** * *** *** |
|* * ** ***** * ** **|
|**** * * * * ** ** * ** * * * |
|**************************************|
----------------------------------------
May the Force be with you.*
----------------------------------------
|* * * * * * * * * * * * * * * |
|* * |
|* ******* ******************* |
|* * * * ** ** |
|** * * * * * ** *** |
|** * * ** * * * * *** |
|* **** * * * *** |
|**** * * ** * ** *** |
|***************************** |
----------------------------------------
****************************************************************/