0% found this document useful (0 votes)
11 views2 pages

Java Slip 3

The document contains two Java code snippets. The first snippet is a JSP page that displays patient details in a table format, while the second snippet demonstrates basic operations on a LinkedList, including adding, removing, and displaying elements in reverse order. Both snippets illustrate the use of Java collections and basic HTML for displaying data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

Java Slip 3

The document contains two Java code snippets. The first snippet is a JSP page that displays patient details in a table format, while the second snippet demonstrates basic operations on a LinkedList, including adding, removing, and displaying elements in reverse order. Both snippets illustrate the use of Java collections and basic HTML for displaying data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Q1

<%@ page import="java.util.*" %>


<%@ page import="java.io.*" %>

<%!
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.*;

public class LinkedListDemo {


public static void main(String[] args) {
// Creating a LinkedList of String objects
LinkedList<String> list = new LinkedList<>();

// Adding some initial elements


list.add("Apple");
list.add("Banana");
list.add("Cherry");
list.add("Date");

// i. Add element at the end of the list


list.addLast("Elderberry");
System.out.println("After adding at the end: " + list);

// ii. Delete first element of the list


list.removeFirst();
System.out.println("After deleting first element: " + list);

// iii. Display the contents of the list in reverse order


System.out.print("List in reverse order: ");
ListIterator<String> iterator = list.listIterator(list.size());
while (iterator.hasPrevious()) {
System.out.print(iterator.previous() + " ");
}
}
}

You might also like