Home Contact Sitemap Todo Money

Alan K Holden

Accomplished Internaut

The IT Zen of Futurama
The IT Zen of Futurama

Bender learns a core principle of Information Technology:

Users clamor for change, but some might complain when you give it to them.

JSP Bingo

At PeopleLink.com, we were going to be changing from ColdFusion 4 to a Java J2EE platform. Management reviewed many J2EE options, like Tomcat and WebSphere, and finally settled on JRun. This meant that our .cfm web pages would become .jsp web pages. I use the words "going to be", because the meltdown of the dot-com economy cut this initiative pretty short.

However, I did have enough time to start learning JSP technology and bump heads with some of the core Java folks we had hired. This is a single-page application which randomly shuffles a collection of words from the 'dot-com leader lexicon' and generates a bingo page. We developers would each print out one of these bingo cards and bring them along so we could play silently during corporate meetings and executive pep talks.

 

Here's the JSP source code:

<%--
bingo.jsp
Alan K Holden [email protected]
Here's a little exercise using JSP and the java Random class
to print a bingo game card that uses a list of words most
likely to be spoken by executives at a keynote or meeting.
The bingo card sequence is shuffled each time the page loads.
--%>
 <%@page import = "java.io.*" %>
<%@page import = "java.util.*" %>
 <%
// total words per page, keep it below the total word count, or you'll loop forever!
int i_twpp = 25;
// words per row
int i_wpr = 5;
// the words; add as many as you like, the code will adjust
ArrayList execuwords = new ArrayList();
execuwords.add("B2C");
execuwords.add("Granularity");
execuwords.add("Monetize");
execuwords.add("Paradigm");
execuwords.add("Incentivize");
execuwords.add("Execute");
execuwords.add("CRM");
execuwords.add("Resource");
execuwords.add("Bandwidth");
execuwords.add("Shareholder");
execuwords.add("Reiterate");
execuwords.add("Burn Rate");
execuwords.add("B2B");
execuwords.add("Restructure");
execuwords.add("Vertical");
execuwords.add("Leverage");
execuwords.add("Quarter (or Q)");
execuwords.add("ROI");
execuwords.add("Right Thing");
execuwords.add("Pipeline");
execuwords.add("Posture");
execuwords.add("Value");
execuwords.add("Modality");
execuwords.add("Vacuum");
execuwords.add("Market Share");
execuwords.add("First Mover");
execuwords.add("Articulate");
execuwords.add("Vis a Vie");
execuwords.add("Milestone");
execuwords.add("Metrics");
execuwords.add("Big Win");
execuwords.add("Ultimately");
execuwords.add("Bottom Line");
execuwords.add("Dillegence");
 // create an array of words already served
int hi_no = execuwords.size();
ArrayList didword = new ArrayList();
for (int i=0; i < hi_no; i++) {
  String s = Integer.toString(i);
  didword.add(s);
}
 // create random number seed
long rns = System.currentTimeMillis();
// create instance of random number generator class
Random Al = new Random(rns);
// I think we're ready for some HTML now...
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
  <title>Corporate Meeting Bingo Card!</title>
</head>
<body bgcolor="#E9E9E2">
<%-- uncomment to output the total word count in the upper corner --%>
<%--<p><font face="Arial" size="1" color="#C0C0C0"> <%out.println(execuwords.size());%></font></p>--%>
<div align="center">
<font face="Arial" size="2" color="#000000">
<h2>Corporate Meeting Bingo Card!</h2>
Never again will you miss another corporate meeting.<br>
You'll sit, listening intently, hanging on every word<br>
about your company's position and its' future. How?
<p>
Simply print out this Bingo card and bring it to the meeting!<br>
Cross off each word when you hear it uttered in reverence by your<br>
CEO, CTO, CFO, CIO, CPO or CCO!
<p>
When you get a complete vertical, horizontal or diagonal row, then<br>
yell out "Bingo" to win the game.
<p>
A new Bingo card is created with every load of the page, so be sure
that all your work mates are playing too!
<p>
</font>
<table border="2" cellspacing="4" cellpadding="4" bgcolor="#ffffff">
<tr>
<%
  // this word's number
  int i_this_no;
  // this word's position in row
  int i_this_pos = 0;
  // count of words served so far
  int i_ssf = 0;
  // start the process
   while (i_ssf < i_twpp) {
    i_this_no = Al.nextInt(hi_no);
    String s = Integer.toString(i_this_no);
    // has word not already been served?
    if (didword.indexOf(s)>-1) {
     // serve the word
     out.println("<td width=\"120\" align=\"center\"><font face=\"Arial\" size=\"2\"> <br><strong>"+execuwords.get(i_this_no)+"</strong><br>  </font></td>");
     // mark word as already served
     didword.set(i_this_no,"");
     // increment number of words served so far
     i_ssf++;
     // increment word's row position
     i_this_pos++;
     // are we at the end of a row?
     if (i_this_pos >= i_wpr) {
      out.println("</tr><tr>");
      i_this_pos = 0;
     }
    }
  // end the process
  }
%>
</tr>
</table>
</div>
</body>
</html>
 

 

My Details
Subscription Settings

Hear about status updates or new posts.