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" "http://www.w3.org/TR/html4/loose.dtd">
<%
	int totNoOfMatches = 15;
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Disciplinary Report</title>
</head>
 
<body>
<table border="1" cellpadding="1" cellspacing="1" bordercolor="#000000">
  <tr>
    <td>Match</td>
	<%for(int i=1;i<=totNoOfMatches;i++){%>
	    <td width="30"><div align="center"><%=i%></div></td>
	<%}%>
  </tr>
  <tr>
    <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>
		<%}else{%>
			<td>&nbsp;</td>
		<%}%>
	<%}%>
  </tr>
</table>
</body>
</html>

Open in new window

discReport.jpg
LVL 1
killdurstAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mick BarryJava DeveloperCommented:
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++; %>
                    Y
                <%}else if (cards==4 || (suspensions>0 && cards==3)) {
                        suspensions++;  
                        cards = 0; %>
                        Suspended
                <%}else {
                       
                <%}%>
        <%}%>

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CEHJCommented:
In which attribute of Player are you storing suspension info?
0
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?
0
Mick BarryJava DeveloperCommented:
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

0
killdurstAuthor Commented:
Yes, your example is very helpful. I'm trying it out right now. Will keep you updated...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.