Java Slip 3
Java Slip 3
<%!
class Patient {
int pNo;
String pName;
String address;
int age;
String disease;
public Patient(int pNo, String pName, String address, int age, String
disease) {
this.pNo = pNo;
this.pName = pName;
this.address = address;
this.age = age;
this.disease = disease;
}
}
%>
<%
List<Patient> patients = new ArrayList<>();
patients.add(new Patient(1, "John Doe", "123 Street, NY", 45, "Flu"));
patients.add(new Patient(2, "Jane Smith", "456 Avenue, LA", 30, "Covid-19"));
patients.add(new Patient(3, "Robert Brown", "789 Road, TX", 50, "Diabetes"));
%>
<html>
<head>
<title>Patient Details</title>
<style>
table { border-collapse: collapse; width: 60%; margin: 20px auto; }
th, td { border: 1px solid black; padding: 10px; text-align: center; }
th { background-color: #f2f2f2; }
</style>
</head>
<body>
<h2 align="center">Patient Details</h2>
<table>
<tr>
<th>PNo</th>
<th>PName</th>
<th>Address</th>
<th>Age</th>
<th>Disease</th>
</tr>
<% for (Patient p : patients) { %>
<tr>
<td><%= p.pNo %></td>
<td><%= p.pName %></td>
<td><%= p.address %></td>
<td><%= p.age %></td>
<td><%= p.disease %></td>
</tr>
<% } %>
</table>
</body>
</html>
Q2
import java.util.*;