Академический Документы
Профессиональный Документы
Культура Документы
import java.util.Scanner;
import java.util.ArrayList;
int i = 0;
int choice,again,again2,accounter;
do{
accounter = ac.nextInt();
switch( accounter){
case 1: {
ar.add(p1);
}break;
case 2: {
if( i == 0){
else
{
System.out.println("Enter Account No. : ");
int id = ac.nextInt();
AccountHolder pp = ar.get(id-1);
do{
choice= ac.nextInt();
switch(choice)
case 1: {
int b = pp.getBalance();
}break;
case 2: {
int d = ac.nextInt();
pp.Deposit(d);
} break;
case 3: {
int W = ac.nextInt();
} break;
again2 = ac.nextInt();
}break;
again = ac.nextInt();
}while(again == 1);
public Bank(int m) {
super(m);
AccountHolder.java
package BankBranch;
int balance,Acc_no;
AccountHolder(int m){
balance = 0;
Acc_no = m;
TaxDeduction(amount);
return amount;
}
else
if(balance != 0){
int b = balance;
balance = 0;
return b;
else
System.out.println("Insufficient Balance");
return -1;
int getBalance(){
return balance;
}
Output:
2. Implement an abstract class stack with methods push, pop , display for two classes :
StaticStack and DynamicStack .
DynamicStack.java
package sdstack;
import java.util.ArrayList;
SDstack.java
package sdstack;
import java.util.Scanner;
public class SDStack {
public static void main(String[] args) {
int ch,op,sd;
Scanner IN=new Scanner(System.in);
System.out.println("Choose Stack :\n1.Static Stack\n2.Dynamic Stack
");
sd=IN.nextInt();
switch(sd)
{
case 1: StaticStack s;
System.out.print("Enter the size of the stack ");
int n=IN.nextInt();
s=new StaticStack(n);
do{
System.out.println("Static Stack of size"+n);
System.out.println("1.Push");
System.out.println("2.Pop");
ch=IN.nextInt();
switch(ch)
{
case 1: System.out.print("Enter the element to
be pushed ");
int elt=IN.nextInt();
s.push(elt);
s.display();
break;
case 2:System.out.println(s.pop());
s.display();
break;
}
System.out.print("Exit(0)/Menu(1)");
op=IN.nextInt();
}while(op==1);
break;
case 2:DynamicStack d=new DynamicStack();
do{
System.out.println("Dynamic Stack ");
System.out.println("1.Push");
System.out.println("2.Pop");
ch=IN.nextInt();
switch(ch)
{
case 1:System.out.print("Enter the element to
be pushed ");
int elt=IN.nextInt();
d.push(elt);
d.display();
break;
case 2:System.out.println(d.pop());
d.display();
break;
}
System.out.print("Exit(0)/Menu(1)");
op=IN.nextInt();
}while(op==1);
break;
default: System.out.println("Invalid Input");
break;
}
}
}
Stack.java
package sdstack;
}
}
@Override
public int pop() {
if(top==-1)
System.out.println("Stack Underflow");
else {
System.out.println("Element Popped : ");
return a[top--];
}
return -1;
}
public void display()
{
for(int i=0;i<=top;i++)
{
System.out.print(a[i]+" ");
}
}
}
Ouput:
JAVASCRIPT PRACTICALS
1. Create a student registration form .Create functions to perform the following checks:
a.) Roll number is a 7 digit numeric value.
b.) Name should be an alphabetical value.
c.) DOB entered in dd/mm/yy format and should be displayed in words.
d.) Check on non-empty fields.
<html>
<head>
<script ="JavaScript">
//alert("hello");
function check_name()
var c= document.getElementById("1").value;
if(!c.match(letters)) {
else
document.getElementById("0").value="";
function check_roll() {
var no = document.getElementById("1").value;
if (no.length!=7 ) {
else
document.getElementById("1").value="";
function check_date( ){
var weekdays=['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'];
var
mm=['January','February','March','April','May','June','July','August','September','October','November','Decemb
er'];
var month=db.getMonth();
</script>
</head>
<body>
</form>
</body>
</html>
Output:
2. Implement a static password protection
<html>
<head>
<title>Login Form</title><br>
<script type="text/javascript">
function check()
var id = document.getElementById("1").value;
else
</script>
</head>
<body>
</body>
</html>
Output:
3. Write a javascript to sort an array using bubblesort. Take the number of elements in
array form the user.
<html>
<head>
<title>BUBBLE SORT</title>
<script type="text/javascript">
function Sort_N(){
var n = document.getElementById("1").value;
arr = str.split(",");
arr2 = arr.map(Number);
var n = arr2.length;
arr2[j-1] = arr2[j];
arr2[j] = temp;
} }
document.getElementById("4").value = arr2.toString();
</script>
</head>
<body>
<form>
</form>
</body>
</html>
Output:
4. Write a javascript to implement stack methods(push and pop).
<html>
<head>
<script language="JavaScript">
arr = [];
function stackpush() {
var n = document.getElementById("1").value;
arr.push(n);
document.getElementById("1").value="";
document.getElementById("4").value=arr.toString();
function stackpop() {
arr.pop();
document.getElementById("4").value=arr.toString();
</script>
</head>
<body>
<form>
</form>
</body>
</html>
Output:
5.Write a javascript
a.)to change the color of the text using setTimeout().
<html>
<head>
<body>
<script language="javascript">
function f1(){
document.getElementById("1").style.color = "#FF0000";
function f2() {
document.getElementById("1").style.color = "#0000ff";
</script>
<form >
</form>
</body>
</html>
Output:
<head>
<title>JavaScript Animation</title>
<script type="text/javascript">
var animate ;
function init(){
imgObj = document.getElementById('myImage');
imgObj.style.position= 'relative';
imgObj.style.left = '0px';
function moveRight(){
function stop(){
clearTimeout(animate);
imgObj.style.left = '0px';
window.onload =init;
//-->
</script>
</head>
<body>
<form>
<img id="myImage"
src="http://www.seedgeeks.com/store/image/cache/data/product/flowers/ox.eye.sunflower2-
500x500_0.jpg"/>
</form>
</body>
</html>
Output:
6. Create a webpage which accepts user information and user comments on the website.
Design the webpage using form elements and check if all the text fields have being
entered with the data else display an alert.
<html>
<head></head>
<title>INFONET SERVICES</title>
<script language="JavaScript">
var c;
function f1(){
for(c=0;c<9;c++){
if(document.my.elements[c].value=="") {
document.my.elements[c].focus();
break;
else {
alert("Welcome");
</script>
<body>
<form name="my">
<input type="radio" id="a3" > I have not purchased anything online but i would consider it<br>
<OPTION ></OPTION></SELECT></br><p>
</form>
</body>
</html>
Output:
JSP PRACTICALS
index.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%!int n;%>
<html>
<body>
<% n=Integer.parseInt(request.getParameter("lineno"));
for(int i=1;i<=n;i++)
{ for(int j=1;j<=i;j++)
{ out.println(j+" "); }
out.println("<br>");
}
%>
</body>
</html>
Output:
2. Make two files as follows:
a. main.html: shows 2 text boxes and 3 radio buttons with values “addition”,”subtraction”
and multiplication.
b. operate.jsp:depending on what the user selects perform the corresponding functions
main.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
</head>
<body>
<form action="operate.jsp">
Enter Number 1: <input type="text" name="no1">
Enter Number 2:<input type="text" name="no2"><br>
Addition: <input type="radio" name="op" value="add"><br>
Subtraction: <input type="radio" name="op"
value="sub"><br>
Multiplication: <input type="radio" name="op"
value="mul"><br><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
operate.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%! int n1,n2;%>
<%! String ch;%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
</head>
<body>
<% n1=Integer.parseInt(request.getParameter("no1"));
n2=Integer.parseInt(request.getParameter("no2"));
ch=request.getParameter("op");
if(ch.equals("add"))
out.println("Addition is: "+(n1+n2));
else if(ch.equals("sub"))
out.println("Subtraction is: "+(n1-n2));
else if(ch.equals("mul"))
out.println("Multiplication is: "+(n1*n2));
%>
</body>
</html>
Output:
time.jsp
library.tld
<?xml version="1.0" encoding="UTF-8"?>
<taglib version="2.1" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd">
<tlib-version>1.0</tlib-version>
<short-name>library</short-name>
<uri>/WEB-INF/tlds/library</uri>
<tag>
<name>uname</name>
<tagclass>pack.Servlet</tagclass>
<body-content>scriptless</body-content>
</tag>
</taglib>
Servlet.java
package pack;
import java.io.IOException;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.io.*;
import java.util.Date;
import javax.servlet.jsp.JspException;
if(d<12)
out.println("Good Morning");
else if(d>=12 && d<=16)
out.println("good afternoon");
else
out.println("good evening");
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Output:
5. Let the user enter a word in a textbox and let her/him select one of even or odd radio
buttons.If he/she selects odd,check the odd positions in the word entered, if they all
contain vowels , then display ‘You Win’ , else display ‘You Lose’. If the user selects even ,
check for vowels in all even positions in the word entered . Use jstl’s ‘fn’ library.
EvenOdd.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
</form></center>
</body>
</html>
Checkpos.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>JSP Page</title>
</head>
<body>
<%
String str1=request.getParameter("str");
String str2=request.getParameter("rad");
int c=Integer.parseInt(str2);
char ch;
int flag=0;
switch(c)
{
case 1: for(int i=0;i<str1.length();i++)
{
if(i%2!=0)
{ ch=str1.charAt(i); if(ch=='a' ||
ch=='A' || ch=='e' || ch=='E' ||ch=='i' || ch=='I' || ch=='o' ||
ch=='O' ||ch=='u' || ch=='U')
{ flag=1; }
else
{ flag=0; break; }
}
}
if(flag==1)
out.println("..You win..");
else
out.println("..You lose..");
break;
case 2 : for(int i=0;i<str1.length();i++)
{
if(i%2==0)
{ ch=str1.charAt(i);
if(ch=='a' || ch=='A' || ch=='e' ||
ch=='E' ||ch=='i' || ch=='I' || ch=='o' || ch=='O' ||ch=='u' ||
ch=='U')
{ flag=1; }
else
{ flag=0; break; }
}
}
if(flag==1)
out.println("..You win..");
else
out.println("..You lose..");
break;
}
%>
</body>
</html>
Output:
6. Create a custom library which contains two tags : <hello>.<choco>.
serv.java
package test;
import java.io.IOException;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.io.*;
import java.util.Date;
import javax.servlet.jsp.JspException;
public class serv extends SimpleTagSupport
{
String texture;
public void setTexture(String texture)
{
this.texture=texture;
}
servlet.java
package test;
import java.io.IOException;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.io.*;
import java.util.Date;
import javax.servlet.jsp.JspException;
tag.tld
<?xml version="1.0" encoding="UTF-8"?>
<taglib version="2.1" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd">
<tlib-version>1.0</tlib-version>
<short-name>tag</short-name>
<uri>/WEB-INF/tlds/tag</uri>
<tag>
<name>hello</name>
<attribute>
<name>name</name>
<required>true</required>
</attribute>
<tagclass>test.servlet</tagclass>
<body-content>scriptless</body-content>
</tag>
<tag>
<name>choco</name>
<attribute>
<name>texture</name>
<required>true</required>
</attribute>
<tagclass>test.serv</tagclass>
<body-content>scriptless</body-content>
</tag>
</taglib>
Jsp.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="ct" uri="/WEB-INF/tlds/tag.tld" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
</head>
<ct:hello name="Ajay"/><br>
<ct:choco texture="Chewy"/><br>
<ct:choco texture="Crunchy"/>
</html>
Output:
7.Create a custom tag “substring” with 3 mandatory attributes “input”,”start”,”end”
which will do substring operation on given input.
jsp.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="ct" uri="/WEB-INF/tlds/lib.tld" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
</head>
<body>
<ct:substring input="People" begin="2" end="5"/>
</body>
</html>
lib.tld
<?xml version="1.0" encoding="UTF-8"?>
<taglib version="2.1" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd">
<tlib-version>1.0</tlib-version>
<short-name>lib</short-name>
<uri>/WEB-INF/tlds/lib</uri>
<tag>
<name>substring</name>
<attribute>
<name>input</name>
<required>true</required>
</attribute>
<attribute>
<name>begin</name>
<required>true</required>
</attribute>
<attribute>
<name>end</name>
<required>true</required>
</attribute>
<tagclass>test.servlet</tagclass>
<body-content>scriptless</body-content>
</tag>
</taglib>
servlet.java
package test;
import java.io.IOException;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.io.*;
import java.util.Date;
import javax.servlet.jsp.JspException;
@Override
public void doTag() throws JspException,IOException
{
JspWriter out=getJspContext().getOut();
String sub="";
for(int i=begin;i<=end;i++)
sub+=input.charAt(i);
out.println("Substring is: "+sub);
}
}
Output:
8. Create a custom tag “reverse” with a mandatory attribute “input” to reverse a string.
jsp.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="ct" uri="/WEB-INF/tlds/tag.tld" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
</head>
<body>
<ct:reversed input="hello"/>
</body>
</html>
tag.tld
<?xml version="1.0" encoding="UTF-8"?>
<taglib version="2.1" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd">
<tlib-version>1.0</tlib-version>
<short-name>tag</short-name>
<uri>/WEB-INF/tlds/tag</uri>
<tag>
<name>reversed</name>
<attribute>
<name>input</name>
<required>true</required>
</attribute>
<tagclass>test.servlet</tagclass>
<body-content>scriptless</body-content>
</tag>
</taglib>
servlet.java
package test;
import java.io.IOException;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.io.*;
import java.util.Date;
import javax.servlet.jsp.JspException;
Output:
9.Create a custom tag “today” that displays today’s date and time .
servletfile.java
package test;
import java.io.IOException;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.io.*;
import java.util.Date;
import javax.servlet.jsp.JspException;
public class servletfile extends SimpleTagSupport
{
public void doTag() throws JspException,IOException
{
JspWriter out=getJspContext().getOut();
Date date=new Date();
out.println(date.toString());
}
}
libfile.tld
<?xml version="1.0" encoding="UTF-8"?>
<taglib version="2.1" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd">
<tlib-version>1.0</tlib-version>
<short-name>libfile</short-name>
<uri>/WEB-INF/tlds/libfile</uri>
<tag>
<name>today</name>
<tagclass>test.servletfile</tagclass>
<body-content>scriptless</body-content>
</tag>
</taglib>
jspfile.jsp:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="ct" uri="/WEB-INF/tlds/libfile.tld" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
</head>
<body>
<ct:today/>
</body>
</html>
Output:
10. Ask a user’s name and age on html page. Then display hello <uname> on jsp page. Ask
user the product they want to buy.
index.html
<!DOCTYPE html>
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
</head>
<body>
<form action="mytag.jsp" method="post">
Enter your name : <input type="text" name="name">
Enter your age : <input type="number" name="age">
<input type="submit">
</form>
</body>
</html>
hello.java
package ques10;
import javax.servlet.jsp.tagext.*;
import javax.servlet.jsp.*;
import java.io.*;
public class hello extends SimpleTagSupport{
private String name;
public void setName(String name)
{
this.name=name;
}
public void doTag() throws JspException,IOException{
JspWriter out=getJspContext().getOut();
out.println("Hello "+name);
}
}
mytag.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="ex" uri="WEB-INF/tlds/uname.tld" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<ex:uname name="${param.name}"/>
<p:product x="${param.sell}" scope="application"/>
<form action="tag.jsp" method="post">
tag.jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<c:out value="${x}"></c:out>
<c:out value="${param.sell}"></c:out>
</body>
</html>
uname.tld
<?xml version="1.0" encoding="UTF-8"?>
<taglib version="2.1" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd">
<tlib-version>1.0</tlib-version>
<short-name>ex</short-name>
<uri>/WEB-INF/tlds/uname</uri>
<!-- A validator verifies that the tags are used correctly at JSP
translation time. Validator entries look like this:
<validator>
<validator-class>com.mycompany.TagLibValidator</validator-class>
<init-param>
<param-name>parameter</param-name>
<param-value>value</param-value>
</init-param>
</validator>
-->
<!-- A tag library can register Servlet Context event listeners in
case it needs to react to such events. Listener entries look
like this:
<listener>
<listener-class>com.mycompany.TagLibListener</listener-class>
</listener>
-->
<tag>
<name>uname</name>
<tag-class>ques10.hello</tag-class>
<attribute>
<name>name</name>
<rtexprvalue>true</rtexprvalue>
</attribute>
<body-content>scriptless</body-content>
</tag>
</taglib>
Output: