import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/Ex2b")
public class Ex2b extends HttpServlet {
private static final long serialVersionUID = 1L;
public Ex2b() {
super();
// TODO Auto-generated constructor stub
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.getWriter().append("
\n" +
" \n" +
" Trial 1 | \n" +
" Trial 2 | \n" +
" Trial 3 | \n" +
" Horizontal sum | \n" +
" Horizontal avg | \n" +
"
");
int x,y,z;
int table[][] = new int[28][3];
int sum[] = new int[28];
double average[] = new double[28];
String avgStr[] = new String[28];
int colSum[] = new int[3];
double colAverage[] = new double[3];
String colAvgStr[] = new String[3];
for (int i = 0; i < 28; i++) {
table[i][0] = (int) (Math.random() * 10);
table[i][1] = (int) (Math.random() * 10);
table[i][2] = (int) (Math.random() * 10);
sum[i] = table[i][0] + table[i][1] + table[i][2];
average[i] = sum[i]/3.0;
avgStr[i] = String.format("%.2f", average[i]);
colSum[0] += table[i][0];
colSum[1] += table[i][1];
colSum[2] += table[i][2];
response.getWriter().append(" \n" +
" " + table[i][0] + " | \n" +
" " + table[i][1] + " | \n" +
" " + table[i][2] + " | \n" +
" " + sum[i] + " | \n" +
" " + avgStr[i] + " | \n" +
"
");
}
colAverage[0] = colSum[0]/28.0;
colAverage[1] = colSum[1]/28.0;
colAverage[2] = colSum[2]/28.0;
colAvgStr[0] = String.format("%.2f", colAverage[0]);
colAvgStr[1] = String.format("%.2f", colAverage[1]);
colAvgStr[2] = String.format("%.2f", colAverage[2]);
response.getWriter().append(" \n" +
" " + colSum[0] + " | \n" +
" " + colSum[1] + " | \n" +
" " + colSum[2] + " | \n" +
" Vertical sum | \n" +
"
\n" +
" \n" +
" " + colAvgStr[0] + " | \n" +
" " + colAvgStr[1] + " | \n" +
" " + colAvgStr[2] + " | \n" +
" Vertical avg | \n" +
"
\n" +
"
");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}