Sunday, 17 June 2012

Frame Set and Frames in HTML webpage

Frames:



Frames are graphical and logical subdivisions of a single web "page" into two or more sections or areas .
Frames make your website less linear but more browse able --- This means that : 
Frames allow one to create web sites which are less "linear" than non-framed sites. But on the other hand 
frames make a site more "browse able"as easy as flipping  through a book. Most

current sites use a two-frame format. The first serves as the site navigation index, while the other is 
the frame holding the selected "content" pages



Good Points of Frames:



  • Making efficient use of frames and maximizing "content" page space .
  • Lets you decide and divide the content on the page . For example you can divide the content on the page from the HTML links on the page .
  • Improves readability for the users as the content is already logically divided into sections.
Frame Set:

The frameset tag in HTML ,<FRAMESET> defines the general layout of a web page that uses frames. <FRAMESET> is used in conjunction with<FRAME> and <NOFRAMES>.

<FRAMESET> creates a table for content in which each rectangle (called a "frame") in the table holds a separate document or a HTML page. In its simplest use, <FRAMESET> states how many columns and/or rows will be in the "table"



Difference between Frames and frameset:

  • The <frame> tag defines one particular window (frame) within a <frameset>.
  • Each <frame> in a <frameset> can have different attributes, such as border, scrolling, the ability to resize, etc.
Frameset attributes:

A. cols  - values can be pixels, %, * -Specifies the number and size of columns in a frameset

B. rows - values can be pixels, %, * -Specifies the number and size of rows in a frameset

Frameset important property:

Frameset can be nested .
In the following example, the outer FRAMESET divides the available space into three columns.
 The inner FRAMESET then divides the second area into two rows of unequal height.
<FRAMESET cols="25%, 25%, 50%">
     ...contents of first frame...
     <FRAMESET rows="40%, 50%">
        ...contents of second frame, first row...
        ...contents of second frame, second row...
     </FRAMESET>
     ...contents of third frame...
</FRAMESET>

NOFRAMES:

This element specifies the content that should be displayed when the frames are not displayed.The user agent that supports frames can only display the content of the this element when it is congirured to not display the frames.

Lets see an example :

<html>
<head>
<title>Demo of NOFRAMES</title>
</head>
<body>
<frameset cols="50%,50%">
<frame src="test1.html"/>
<frame src="test2.html"/>
<noframes>
<p>Hey ! This is the non frame version of the document</p>
</noframes>
</frameset>
</body>
</html>




Vertical use of Frames:


Example.html

<!DOCTYPE html>
<html>
<frameset cols="20%,70%">
<frame src="C:\Users\SunShine\Desktop\New folder\nav.html"/>
<frame src="C:\Users\SunShine\Desktop\New folder\content.html"/>
</frameset>
</html>


nav.html



<html>
<head>
<title>Nav</title>
<body bgcolor=”red”>
<h1>Navigation area</h1>
<ul>
<li><a href=”#”>some</a></li> // # means empty link
<li><a href=”#”>something</a></li>
<li><a href=”#”>something else</a></li>
</ul>
</body>
</head>
</html>



content.html



<html>
<head>
<title>Nav</title>
<body bgcolor=”red”>
<h1>Navigation area</h1>
<ul>
<li><a href=”#”>some</a></li>
<li><a href=”#”>something</a></li>
<li><a href=”#”>something else</a></li>
</ul>
</body>
</head>
</html>




Horizontal use of Frames:



Example.html

<!DOCTYPE html>
<html>
<frameset rows="20%,70%">
<frame src="C:\Users\SunShine\Desktop\New folder\nav.html"/>
<frame src="C:\Users\SunShine\Desktop\New folder\content.html"/>
</frameset>
</html>

nav.html

<html>
<head>
<title>Nav</title>
<body bgcolor=”red”>
<h1>Navigation area</h1>
<ul>
<li><a href=”#”>some</a></li> // # means empty link
<li><a href=”#”>something</a></li>
<li><a href=”#”>something else</a></li>
</ul>
</body>
</head>
</html>

content.html

<html>
<head>
<title>Nav</title>
<body bgcolor=”red”>
<h1>Navigation area</h1>
<ul>
<li><a href=”#”>some</a></li>
<li><a href=”#”>something</a></li>
<li><a href=”#”>something else</a></li>
</ul>
</body>
</head>
</html>

hey guys  i have uploaded a video on the same topic on you tube : http://www.youtube.com/watch?v=0wWMcmJDGfQ

Part 1:


Part 2:



Saturday, 16 June 2012

DHTML - Dynamic Html


• Dynamic HTML is a combination of Hypertext Markup Language (HTML), Cascading Style
Sheets (CSS), and JavaScript.
• HTML provides document structure and context for the information contained in a Web page.
• CSS provides the details on how to present that information.
• JavaScript provides the interactivity and dynamism.


Cascading Style Sheet (CSS)

Cascading refers to a certain set of rules that browsers use, in cascading order, to determine how to use the style information. Such a set of rules is useful in the event of conflicting style information because the rules would give the browser a way to determine which style is given precedence.

• CSS provides a rich selection of presentation effects that can be applied to all HTML elements, such as color, background, margins,and borders.
• With CSS, Web developers can set indents on paragraphs, specify a default font for an entire
Web site with one line of code, use small caps,assign an image as a bullet for a list item, and accomplish many more things that are impossible with HTML alone.


Types of CSS:


  1.  Embedded or Internal Style sheet
  2.  External or Linked Style sheet
  3.   Inline style sheet



Benefits:
•Authors and Web site managers may share style sheets across a number of documents (and sites).
•Authors may change the style sheet without requiring modifications to the document.
•User agents may load style sheets selectively (based on media descriptions).
1.Embedded or Internal Style Sheet:

•You can put style sheet rules in the head of the document by <style>.

example.html
<head>
<style>
p { color: red; font-size:120%; }
</style>
</head>
<body>
<p>This is a paragraph</p>
</body>


2. External or Linked Style Sheet

You can separate style sheets from HTML documents. Style sheet files are imported to HTML documents by <link>.

[example.html]

<head>
<link rel="stylesheet" type="text/css" href="example.css">
</head>
[example.css]
p{ color: red; foto-size: 120%; }


3.Inline Style Sheet

•The start tags can contain style sheet rules directly in HTML documents by the style attribute.

[example.html]

<p style="color: red; font-size:120%; ">
This is a paragraph</p>






CSS syntax

•This syntax has two parts, the selector and the declaration.
Selector: Specifies the target of styling.
Declaration: Specifies the property and value.
•Declaration is contained between {" ... "}.
•Declaration end with a semicolon.

p{ color: red; }


HTML

•Hyper Text Markup Language (HTML) Basics
HTML is a “mark-up language”
You add the mark-up tags to your text document
HTML is a language of mark-up “tags” in angle brackets: <>
each tag has a name and may have one or more quoted attributes
eg. <p class=”thesis” style=”color: red”>
Tags usually come in pairs (with some exceptions)
<html>...</html>, <body>...</body>, <p>...</p>, <hr>, <br>
Web pages are free-form input; line breaks can be used most anywhere and don't affect the appearance of the document
Yes, your entire page could be a single line of text!


JavaScript

JavaScript was designed to add interactivity to HTML pages
JavaScript is a scripting language
A scripting language is a lightweight programming language
JavaScript is usually embedded directly into HTML pages
JavaScript is an interpreted language (means that scripts execute without preliminary compilation)
Everyone can u.se JavaScript without purchasing a license

• JavaScript brings dynamism and interactivity to DHTML.
• Not only can it provide interactivity with event handlers, it can also modify document object properties on the fly, pop up windows, and write content dynamically.
• In the HTML arena, JavaScript is primarily used to modify stylesheet properties on the fly, after a Web page is loaded, to create animations and special effects.

What JavaScript can do?

•JavaScript gives HTML designers a programming tool - HTML authors are normally not programmers, but JavaScript is a scripting language with a very simple syntax! Almost anyone can put small "snippets" of code into their HTML pages
•JavaScript can react to events - A JavaScript can be set to execute when something happens, like when a page has finished loading or when a user clicks on an HTML element
•JavaScript can read and write HTML elements - A JavaScript can read and change the content of an HTML element
•JavaScript can be used to validate data - A JavaScript can be used to validate form data before it is submitted to a server. This saves the server from extra processing
•JavaScript can be used to detect the visitor's browser - A JavaScript can be used to detect the visitor's browser, and - depending on the browser - load another page specifically designed for that browser
•JavaScript can be used to create cookies - A JavaScript can be used to store and retrieve information on the visitor's computer


DHTML EXAMPLE:

change background color: Develop a DHTML page to display mouse over 2 squares and background color will change according to the color of the square.

<html>
<head>
<script type="text/javascript">
function bgChange(bg) {
document.body.style.background=bg;
}
</script>
</head>
<body>
<b>Mouse over the squares and the background color will change!</b>
<table width="300" height="100">
<tr><td onmouseover="bgChange('red')“ onmouseout="bgChange('transparent')"
bgcolor="red"> </td>
<td onmouseover="bgChange('blue')“ onmouseout="bgChange('transparent')"
bgcolor="blue"> </td>
<td onmouseover="bgChange('green')“ onmouseout="bgChange('transparent')"
bgcolor="green"> </td>
</tr>
</table>
</body>
</html>



Friday, 15 June 2012

Binary Search Tree


  • A search tree is a data structures that support many dynamic-set operations.Includes operations SEARCH, MINIMUM, MAXIMUM, PREDECESSOR, SUCCESSOR, INSERT, DELETE. Thus a search tree can be used both as a dictionary and as a priority queue
  • Can be used as both a dictionary and as a priority queue.
  • Basic operations take time proportional to the height of the tree.
  • For complete binary tree with n nodes: worst case (lg n).
  • For linear chain of n nodes: worst case (n).
Properties:

  • The left subtree of a node contains only nodes with keys less than the node's key.
  • The right subtree of a node contains only nodes with keys greater than or equal to the node's key.
  • Both the left and right subtrees must also be binary search trees.

Advantages:

The major advantage of binary search trees over other data structures is that the related sorting algorithms and search algorithms such as in-order traversal can be very efficient.

Applications:

Binary search trees are a fundamental data structure used to construct more abstract data structures such as :
1.sets
2. multi sets
3. associative arrays.

Types:
There are many types of binary search trees. 
1.AVL trees 
2.red-black trees 
They are both forms of self-balancing binary search trees. 
Two other titles describing binary search trees are that of a complete and degenerate tree.
A complete tree is a tree with n levels, where for each level d <= n - 1, the number of existing nodes at level d is equal to 2d. This means all possible nodes exist at these levels. An additional requirement for a complete binary tree is that for the nth level, while every node does not have to exist, the nodes that do exist must fill from left to right.
A degenerate tree is a tree where for each parent node, there is only one associated child node. What this means is that in a performance measurement, the tree will essentially behave like a linked list data structure.

Working with Binary Search Tree:


Binary search trees are an important data structure for dynamic sets.
• Accomplish many dynamic-set operations in O(h) time, where h = height of tree.
• We can  represent a binary tree by a linked data structure in which each node is an object.
• root[T ] points to the root of tree T .
• Each node contains the fields
• key (and possibly other satellite data).
• left: points to left child.
• right: points to right child.
• p: points to parent. p[root[T ]] = NIL.
• Stored keys must satisfy the binary-search-tree property.
• If y is in left subtree of x, then key[y] ≤ key[x].
• If y is in right subtree of x, then key[y] ≥ key[x].
The binary-search-tree property allows us to print keys in a binary search tree in
order, recursively, using an algorithm called an inorder tree walk. Elements are
printed in monotonically increasing order.


How INORDER-TREE-WALK works:
• Check to make sure that x is not NIL.
• Recursively, print the keys of the nodes in x’s left subtree.
• Print x’s key.
• Recursively, print the keys of the nodes in x’s right subtree.
INORDER-TREE-WALK(x)
if x = NIL
then INORDER-TREE-WALK(left[x])
print key[x]
INORDER-TREE-WALK(right[x])

Operations:

1. Searching
Searching a binary search tree for a specific value can be a recursive or iterative process. This explanation covers a recursive method.
We begin by examining the root node. If the tree is null, the value we are searching for does not exist in the tree. Otherwise, if the value equals the root, the search is successful. If the value is less than the root, search the left subtree. Similarly, if it is greater than the root, search the right subtree. This process is repeated until the value is found or the indicated subtree is null. If the searched value is not found before a null subtree is reached, then the item must not be present in the tree.
Searching
TREE-SEARCH(x, k)
if x = NIL or k = key[x]
then return x
if k < key[x]
then return TREE-SEARCH(left[x], k)
else return TREE-SEARCH(right[x], k)
Initial call is TREE-SEARCH(root[T ], k).
2. Insertion
Insertion begins as a search would begin; if the root is not equal to the value, we search the left or right subtrees as before. Eventually, we will reach an external node and add the value as its right or left child, depending on the node's value. In other words, we examine the root and recursively insert the new node to the left subtree if the new value is less than the root, or the right subtree if the new value is greater than or equal to the root.

TREE-INSERT(T, z)
y ← NIL
x ← root[T ]
while x = NIL
do y ← x
if key[z] < key[x]
then x ← left[x]
else x ← right[x]
p[z] ← y
if y = NIL
then root[T ] ← z Tree T was empty
else if key[z] < key[y]
then left[y] ← z
else right[y] ← z
• To insert value v into the binary search tree, the procedure is given node z, with
key[z] = v, left[z] = NIL, and right[z] = NIL.
• Beginning at root of the tree, trace a downward path, maintaining two pointers.
• Pointer x: traces the downward path.
• Pointer y: “trailing pointer” to keep track of parent of x.
• Traverse the tree downward by comparing the value of node at x with v, and
move to the left or right child accordingly.
• When x is NIL, it is at the correct position for node z.
• Compare z’s value with y’s value, and insert z at either y’s left or right, appropriately.
3. Deletion

There are three possible cases to consider:
  • Deleting a leaf (node with no children): Deleting a leaf is easy, as we can simply remove it from the tree.
  • Deleting a node with one child: Remove the node and replace it with its child.
  • Deleting a node with two children: Call the node to be deleted N. Do not delete N. Instead, choose either its in-order successor node or its in-order predecessor node,R. Replace the value of N with the value of R, then delete R.

TREE-DELETE(T, z)
Determine which node y to splice out: either z or z’s successor.
if left[z] = NIL or right[z] = NIL
then y ← z
else y ← TREE-SUCCESSOR(z)
x is set to a non-NIL child of y, or to NIL if y has no children.
if left[y] = NIL
then x ← left[y]
else x ← right[y]
y is removed from the tree by manipulating pointers of p[y] and x.
if x = NIL
then p[x] ← p[y]
if p[y] = NIL
then root[T ] ← x
else if y = left[p[y]]
then left[p[y]] ← x
else right[p[y]] ← x
If it was z’s successor that was spliced out, copy its data into z.
if y = z
then key[z] ← key[y]
copy y’s satellite data into z
return y
4. Traversal

Once the binary search tree has been created, its elements can be retrieved in-order by recursively traversing the left subtree of the root node, accessing the node itself, then recursively traversing the right subtree of the node, continuing this pattern with each node in the tree as it's recursively accessed. As with all binary trees, one may conduct a pre-order traversal or a post-order traversal, but neither are likely to be useful for binary search trees.

How INORDER-TREE-WALK works:
• Check to make sure that x is not NIL.
• Recursively, print the keys of the nodes in x’s left subtree.
• Print x’s key.
• Recursively, print the keys of the nodes in x’s right subtree.
INORDER-TREE-WALK(x)
if x = NIL
then INORDER-TREE-WALK(left[x])
print key[x]
INORDER-TREE-WALK(right[x])


Wednesday, 13 June 2012

Binary Search Tree in C ++


/*
* Performing various operation on Binary search tree
* Author : Ravi Kiran
* Date : 4 April 2011
—————–Steps——————————–
* Create :- Create Binary Search tree
* Perform Various operations on Binary Search tree created
* Display the Binary search tree
*/
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>

void insert(struct node*, int);
int MIN(struct node*);
int MAX(struct node*);
void search(struct node*, int);
void inorder(struct node*);
void preorder(struct node*);
void postorder(struct node*);

struct node
{
int data;
node *left;
node *right;
};
struct node*root = NULL;

void main()
{
int a, ele;
char ans;
clrscr();
cout<<"\n\n\nDo you wish to continue?"<<endl;
cin>>ans;
while((ans=='y') || (ans =='Y'))
{
cout<<"What operation do you wish to perform ...?"<<endl;
cout<<"Please enter your choice ..."<<endl;
cout<<"\n\n\n\t\t\t******MAIN MENU******"<<endl;
cout<<"\n\n\n\t\t\t1.INSERT"<<endl;
cout<<"\t\t\t3.SEARCH"<<endl;
cout<<"\t\t\t4.MIN"<<endl;
cout<<"\t\t\t5.MAX"<<endl;
cout<<"\t\t\t6.INORDER TRAVERSING"<<endl;
cout<<"\t\t\t7.POSTORDER TRAVERSING"<<endl;
cout<<"\t\t\t8.PREORDER TRAVERSING"<<endl;
cout<<"\t\t\t9.EXIT"<<endl;
cin>>a;
switch(a)
{
case 1:
cout<<"\nPlease enter the element to be inserted\n";
cin>>ele;

if(root==NULL)
{
root=(struct node*)malloc(sizeof(struct node));
root->data=ele;
root->left=root->right=NULL;
}
else
insert(root,ele);
break;
case 2:
cout<<"\nPlease enter the element to be searched\n";
cin>>ele;
search(root,ele);
break;
case 3:cout<<"The MIN value of the tree is:";
cout<<MIN(root)<<endl;
break;
case 4:cout<<"The MAX value of the tree is:" ;
cout<< MAX(root)<<endl;
break;
case 5:
cout<<"\nPerforming INORDER traversal\n";
inorder(root);
break;
case 6:
cout<<"\nPerforming POSTORDER traversal\n";
postorder(root);
break;
case 7:
cout<<"\nPerforming PREORDER traversal\n";
preorder(root);
break;
case 8:
exit(0);
default: cout<<"\nOops! Wrong choice ....!";
}
}
getch();
}
void insert(struct node* root, int element)
{
if(element<root->data)
{
if(root->left==NULL)
{
struct node* newnode;
newnode=(struct node *)malloc(sizeof(struct node));
newnode->data=element;
newnode->left=newnode->right=NULL;
root->left=newnode;
}
else
insert(root->left,element)  ;

}
else if(element>root->data)
{
if(root->right==NULL)
{
struct node* newnode;
newnode=(struct node *)malloc(sizeof(struct node));
newnode->data=element;
newnode->left=newnode->right=NULL;
root->right=newnode;
}
else
insert(root->right,element);
 }
}

void search(struct node *root, int element)
{
if(root->data==element)
cout<<"\t\tFound...! "<<endl<<endl<<endl;
else if(root->left!=NULL)
{
search(root->left,element);
}
else if(root->right!=NULL)
{
search(root->right,element);
}
else
cout<<"Element not found ...!"<<endl;
}

int MIN(struct node *root)
{
int min=root->data;
while(root->left!=NULL)
{
root=root->left;
min=root->data;
}
return(min);

}

int MAX(struct node *root)
{
int max=root->data;
while(root->right!=NULL)
{
root=root->right;
max=root->data;
}
return(max);
}

void inorder(struct node *root)
{
if(root!=NULL)
{
if(root->left!=NULL)
inorder(root->left);
cout<<root->data<<endl;
if(root->right!=NULL)
inorder(root->right);
}
else
cout<<"OOps ! Tree is empty"<<endl;
}

void preorder(struct node* root)
{
if(root!=NULL)
{
cout<<root->data;
if(root->left!=NULL)
inorder(root->left);
if(root->right!=NULL)
inorder(root->right);
}
else
cout<<"OOps ! Tree is empty"<<endl;
}


void postorder(struct node* root)
{
if(root!=NULL)
{
if(root->left!=NULL)
inorder(root->left);
if(root->right!=NULL)
inorder(root->right);
cout<<root->data;
}
else
cout<<"OOps ! Tree is empty"<<endl;
}

Polynomial evaluation using Linked List in C







Here are the instructions of the program:

Recall that a polynomial is a sum of terms in the form, f(x) = a0x0 + a1x1 + a2x2 + … + anxn. You are to write a program that will manipulate polynomials. The application should instantiate polynomials as linked lists of terms. The application should allow the user to do the following

1. Build a polynomial by entering it term by term. The function must first check to see if there is a term with that exponent in the polynomial (find). If there is not, the function will insert the term. If there is, the function will first remove the existing term and then insert the new term.

2. Input polynomials to produce a new polynomial. The function will be passed the polynomial and return their sum.

3. Print out the polynomial in the form
term1 + term2 + … + termN

4. Evaluate the polynomial that was the result of the given polynomial expression  a value from the user

5. Clear the polynomials and start again

The user should be able to repeat the process above as many times as he or she wants.

Now I have finished the implementation and the header files:

/*
* Evaluation of polynomial using singly linked list
* Author :Ravi Kiran 
* on:5 April 2011
—————–STEPS——————————–
* Create :- Inputs : Integer coefficient and power of x
* Evaluation of polynomial
* Display the polynomial
*/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>


struct node *create();
float evaluate(struct node *);
float traversal(struct node *);


struct node
{
  int coeff, expo;
  char variable;
  struct node *next;
};


void main()
 {
  struct node *h;


  clrscr();
  h = create();
  printf("\nThe Result of your polynomial is :%f",traversal(h));


  getch();
 }


struct node *create()
{
  int again;
  struct node *temp, *first, *newnode;
  first=(struct node*)malloc(sizeof(struct node));


  printf("\nEnter coefficient and exponent of the node:\n");
  scanf("%d %s %d",&(first->coeff),&(first->variable),&(first->expo));
  first->next = NULL;
  temp = first;


  printf("\nDo you want to create next node?(YES=1)/(NO=0)\n");
  scanf("%d",&again);
  while(again)
   {
newnode=(struct node *)malloc(sizeof(struct node));
printf("Enter coefficient,variable and exponent of next node\n");
scanf("%d %s %d",&newnode->coeff,&newnode->variable,&newnode->expo);
newnode->next = NULL;


temp->next=newnode;
temp=newnode;


printf("\nDo you want to create next node?(YES=1)/(NO=0)\n");
scanf("%d",&again);
   }


return(first);
}


float traversal(struct node *first)
{
struct node *temp;
float sum,x;
sum=0;
temp=first;
while(temp!= NULL)
{
x=evaluate(temp);
temp=temp->next;
sum=sum+x;
}
return(sum);
}




float evaluate(struct node *temp)
{
float value, z;
int exp = temp->expo;
int coeff = temp->coeff;


printf("\nEnter the value of variable %c : ",temp->variable);
scanf("%f",&value);


z = powl(value,exp);


return(z * coeff);
}

JavaScript & Simple HTML calculator using javascript


Javascript:
What can a JavaScript Do?
  • JavaScript gives HTML designers a programming tool - HTML authors are normally not programmers, but JavaScript is a scripting language with a very simple syntax! Almost anyone can put small "snippets" of code into their HTML pages
  • JavaScript can put dynamic text into an HTML page - A JavaScript statement like this: document.write("<h1>" + name + "</h1>") can write a variable text into an HTML page
  • JavaScript can react to events - A JavaScript can be set to execute when something happens, like when a page has finished loading or when a user clicks on an HTML element
  • JavaScript can read and write HTML elements - A JavaScript can read and change the content of an HTML element
  • JavaScript can be used to validate data - A JavaScript can be used to validate form data before it is submitted to a server. This saves the server from extra processing
  • JavaScript can be used to detect the visitor's browser - A JavaScript can be used to detect the visitor's browser, and - depending on the browser - load another page specifically designed for that browser
  • JavaScript can be used to create cookies - A JavaScript can be used to store and retrieve information on the visitor's computer
  •  Imperative and structured
  •  Dynamic
  •  Functional
  • Prototype-based
  •  Miscellaneous
  • Vendor-specific extensions

Description : The user inputs 2 numbers into 2 text boxes selects the operation he/ she wishes to perform and the result is displaced in the third text box.


/**
 *
 * @author ravikiran
 */
function division()
<body>
<input type="button" value="Add" onclick="javascript:add();">

<input type="button" value="Add" onclick="javascript:add();">
<html>
<head>
<title>SIMPLE CALCULATOR USING JAVASCRIPT</title>
<script language="javascript" type="text/javascript">
function multiply()
{
a=Number(document.calculator.number1.value);
b=Number(document.calculator.number2.value);
c=a*b;
document.calculator.total.value=c;
}
function add()
{
a=Number(document.calculator.number1.value);
b=Number(document.calculator.number2.value);
c=a+b;
document.calculator.total.value=c;
}
function subtract()
{
a=Number(document.calculator.number1.value);
b=Number(document.calculator.number2.value);
c=a-b;
document.calculator.total.value=c;
}

{
a=Number(document.calculator.number1.value);
b=Number(document.calculator.number2.value);
c=a/b;
document.calculator.total.value=c;
}
</script>
</head>

<form name="calculator">
Number 1:<input type="text" name="number1"><br/>
Number 2:<input type="text" name="number2"><br/>
Result:<input type="text" name="total"><br/><br/>

<input type="button" value="Multiply" onclick="javascript:multiply();"><br/>
<input type="button" value="divide" onclick="javascript:division();">
<input type="button" value="subtract" onclick="javascript:subtract();">
</form>
</body>
</html>


Simple Bank Account - Java


Account.java
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bank;

/**
 *
 * @author ravikiran
 */
public class Account {
    private long AccNumber,balance;
    private String AccHolder;

    public Account(long num,long bal,String name){
        AccNumber=num;
        balance=bal;
        AccHolder=name;
    }
    public void withdraw(long amount)throws InsufficientFundsException
    {
     
             if(amount>balance)
                 throw new InsufficientFundsException(amount);
             else
             {
                 balance=balance-amount;
            System.out.print("The current balance is"+balance);

            }
    }
      public void deposit(long amount)throws InvalidTransactionException
              {

             if(amount<=0)
                 throw new InvalidTransactionException(amount);
             else
             {
                 balance=balance+amount;
            System.out.print("The current balance is"+balance);

            }

    }
}
 
InsufficientFundsException.java



/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bank;

import java.util.Scanner;

/**
 *
 * @author ravikiran
 */
class InsufficientFundsException extends Exception {
    long amt;
    public InsufficientFundsException(long amount)
    {
     
       
        amt=amount;
    }
   public  String tostring(){
        return"InsufficientFundsException";
    }


}


InvalidTransactionException.java
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bank;

/**
 *
 * @author ravikiran
 */
class InvalidTransactionException extends Exception {
    long amt;
    public  InvalidTransactionException(long amount)
    {


        amt=amount;
    }
   public  String tostring(){
        return" Invalid Transaction Exception";
    }


}


Main.java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bank;

import java.util.Scanner;
import javax.swing.JOptionPane;

/**
 *
 * @author ravikiran
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        System.out.println("select your operation");
        System.out.println("1.withdraw");
        System.out.println("2.Deposit");

        Account a=new Account(215,20000,"ravi");
        Scanner input=new Scanner(System.in);
        int b=input.nextInt();

        switch(b)
        {

        case 1:
        try{

            a.withdraw(20000);
        }
        catch(InsufficientFundsException e){
            JOptionPane.showMessageDialog(null,"Dear Customer You Have insufficient amount in your Account.","Error",JOptionPane.ERROR_MESSAGE);
            
        }
        break;
        case 2:try {

            a.deposit(10);
        }
        catch(InvalidTransactionException e){
            JOptionPane.showMessageDialog(null,"Dear Customer You Entered Invalid Amount","Error",JOptionPane.ERROR_MESSAGE);
            
        }
        break;
        default: System.out.print("Invalid operation");
        }
    }
}