Link to home
Start Free TrialLog in
Avatar of killdurst
killdurst

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
In which attribute of Player are you storing suspension info?
Avatar of killdurst
killdurst

ASKER

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

Yes, your example is very helpful. I'm trying it out right now. Will keep you updated...