generateBarcode Precondition The input String is not null Po
generateBarcode(...)
*Precondition: The input String is not null.
*Post condition: the returned string is exactly 12 characters in length where each character is a digit [0-9]. The string should be constructed using the following rules:
-All characters in the string will be converted to numbers [0-26] e.g. \'A\' or \'a\' =1, \'Z\' or \'z\' =26. All the other character that are not letters =0.
-Groups of 3 consecutive characters numbers will be added together to form a new number; this value will be converted to a String of two digits(pad with a 0 in front of necessary)
-The next group of 3 this is to be done to is two characters later, and so on until 12 total characters have been made. This represents the barcode (If there are not enough character numbers to do this assume 0.
This is for Java
generateBarcode Example: String Character 165 9 14 5 0 19 15 12 0 0 0 39 34 00 Added Groups: Added Groups: 19 27 Final Barcode String: 391934270000\"Solution
import com.onbarcode.barcode.AbstractBarcode;
import com.onbarcode.barcode.Code128;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
public class BarcodeServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException
{
try {
Code128 barcode = new Code128();
barcode.setData(\"0123456789\");
ServletOutputStream servletoutputstream = response.getOutputStream();
response.setContentType(\"image/jpeg\");
response.setHeader(\"Pragma\", \"no-cache\");
response.setHeader(\"Cache-Control\", \"no-cache\");
response.setDateHeader(\"Expires\", 0);
// Generate Code-128 barcode & output to ServletOutputStream
barcode.drawBarcode(servletoutputstream);
}
catch (Exception e) {
throw new ServletException(e);
}
}
}


