Java / JSP Question

I have a JSP page which I have created just for experts exchange to describe my question. Below is the code. It displays a disciplinary table for a player in a soccer competition. See pic below. This report indicates that Player A received a yellow card for match 1, 2, 3, 4, 7, 8 and 9. The competition rules states that once a player has collected 4 yellow cards, he will be suspended for a match. After serving that one match suspension, if he collects 3 more yellow cards, he will be suspended for another match. Player A got to play in match 6 without collecting a yellow card.

What I want is to display the word "Suspended" in the cell below match 5 and 10.

I tried to create an int to count the total number of yellow cards Player A has collected, and using that count, display the word "Suspended", but this method will display the word for match 6 as well, which is what I don't want.

So how do I display the word "Suspended" for match 5 and 10?
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
	int totNoOfMatches = 15;
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Disciplinary Report</title>
<table border="1" cellpadding="1" cellspacing="1" bordercolor="#000000">
	<%for(int i=1;i<=totNoOfMatches;i++){%>
	    <td width="30"><div align="center"><%=i%></div></td>
    <td>Player A </td>
	<%for(int i=1;i<=totNoOfMatches;i++){%>
		<%if(i==1 || i==2 || i==3 || i==4 || i==7 || i==8 || i==9){%>
		    <td bgcolor="#FFFF00"><div align="center">Y</div></td>

Open in new window

Who is Participating?
objectsConnect With a Mentor Commented:
keep a tally of the yellow cards and reset it when they are suspended

             int cards = 0;
             int suspensions = 0;
             for(int i=1;i<=totNoOfMatches;i++){%>
                <%if(i==1 || i==2 || i==3 || i==4 || i==7 || i==8 || i==9){
                         cards++; %>
                <%}else if (cards==4 || (suspensions>0 && cards==3)) {
                        cards = 0; %>
                <%}else {

In which attribute of Player are you storing suspension info?
killdurstAuthor Commented:
That's the issue... we don't store the suspension info for a player. The suspension rules are just for this disciplinary report. The rules for a competition exist in a separate table. The rules are like these:

4 yellows = 1 suspension
7 yellows = 1 suspension
9 yellows = 1 suspension
1 red = 2 suspensions

If a player gets 3 more yellows after his first suspension (4+3 = 7), he gets 1 more suspension. Once he has 9 yellows, his tally will be reset to 0, so he will be suspended again once he's picked up another 4 yellows.

A player suspension for a match is not stored in the database because the organisers might shift the order of the match around at the last minute. For example, match 6 might be played before match 5.

Should I store a player's suspension in a table or what?
no, you don't really need to, you already have all the data you need.
Just keep a running count as you loop as I showed above

killdurstAuthor Commented:
Yes, your example is very helpful. I'm trying it out right now. Will keep you updated...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.