Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

Java

Uploaded by

saritha
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Java

Uploaded by

saritha
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 55

Jaya Prakash Narayan Educational Society Group of Institutions

Faculty of Engineering / Faculty of Pharmacy


Department:

LABORATORY MANUAL
A. OVERVIEW
Year / Semester : B.Tech – 2/2 Sem Academic Year: 2012-13
Laboratory Title: Object Oriented Programming Laboratory Code: 54609
Total Contact Hours: 36 Duration of SEE: 03 Hours

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


Mid Term / Quiz. Marks: 25 Marks SEE Marks: 50 Marks
Lesson Plan Author: A.SWAPNA Sign Date : 10/12/12
Checked By: Sign Date :
M.SWETHA

B. OBJECTIVES
1. To plan the Laboratory activities so as to complete the experiments on time.
2. To write & complete the records at the end of each experiment.
3. To prepare the laboratory manual.

C. DESCRIPTION
1. LEARNING OBJECTIVES:
 To do the program in java, students should know the programming in C language
 Should know the OOP concepts

2. LEARNING OUTCOMES:
 To make the students learn an object oriented way of solving problems
 To teach the student to write programs in java to solve the problems

3. PREREQUISITES:
1. They should know how to compile the java programs
2. They should know how to run the java programs

4. BASE COURSE:
Object Oriented Programming

5. INTRODUCTION

a)All the computers in the lab are P4 processor


b)All the computers are installed with JDK software

6. RESOURSES REQUIRED
 Good configured PC's

 JDK software

7. GENERAL INSTRUCTIONS:
 Maintain Lab records
 Maintain the observation for the programs and bring to the lab when the lab is
working
8. CONTENTS:
Expt Date Date
No. Planned Conducted
1 Write a Program To print the Fibonacci series up to given 17/12/12

Page No.: 1/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
numbers 20/12/12

2 Write a Program To print the Prime Numbers up to given 17/12/12


numbers 20/12/12

3 Write a program for quadratic equation 24/12/12


27/12/12

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


4 Write an applet To handling the mouse events 24/12/12
27/12/12
5 Write a Program To find the product of matrices 31/12/12
03/01/13
6 Write a program that display each integer and sum of all 31/12/12
integers using stringtokenizer 03/01/13

7 Write a Program That allow user to draw the line, rectangle 07/01/13
and ovals 10/01/13

8 Write a Program To check whether the given string is 07/01/13


Palindrome or not. 10/01/13

9 Write a Program To sort the given list of names 14/01/13


17/01/13
10 Write a java program to make frequency count of words in a 14/01/13
given text. 17/01/13

11 Write a Program That reads on a file and display the 21/01/13


information that whether the file exists or not, to display the 24/01/13
information about the file and find the type of file whether
readable, writable and the length of bytes.

12 Write a Program That reads a file and displays the file on 21/01/13
the screen within line number before each line 24/01/13

13 Write a Program That prints a number of 28/01/13


characters ,words,lines in that file 31/01/13

14 Write a Program That implements a stack ADT 04/02/13


07/02/13
15 Write a program that implements infix expression into 18/02/13
postfix expression 21/02/13

16 Develop an applet that receives an integer in one text field, 25/02/13


and computes as factorial value and returns it in another 28/02/13
text field,when the button named “Compute” is clicked

17 Write an applet that displays a simple message 04/03/13


07/03/13
18 Write an applet that displays a simple message 11/03/13
14/03/13
19 Write a java program for handling mouse events. 18/03/13
21/03/13
20 Write a java program that creates three threads.First thread 25/03/13
displays”Good Morning” every one second,the second thread 28/03/13
Page No.: 2/55
Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
displays “Hello” every two seconds and the third thread
displays “Welcome” every three seconds
21 Write a java program that correctly implements producer 04/04/13
consumer problem using the concept of inter thread 08/04/13
communication

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


Evaluation Scheme
1.Lab activity – 1 Mark allotted to each experiment – 15 Marks.
2.Internal exam at the end of sem – 10 Marks.
3.Sem End Exam – 50 Marks – External examiner will conduct exam.

10. REFERENCE:
1. Java How to Program, sixth Edition, H.M.Dietel and P.J.Dietel, Pearson Education/PHI
2. Programming with JAVA, M.P.Bhave and S.A.Patekar, pearson Education
3. Java Programming, D S Malik, cengage learning, Indian edition.

D. EXPERIMENTS

1. EXPERIMENT NO: Date Planned Date Conducted Marks


I 17/12/12
20/12/12

2. TITLE:
 Write a Program To print the Fibonacci series up to given numbers

3. LEARNING OBJECTIVES:
 They will learn how to write the Fibonacci series using java

4. AIM:
 Write a java program to generate the Fibonacci series, given number of n values

5. MATERIAL / EQUIPMENT REQUIRE ...:


 A good configured PC
 JDK software

6. THEORY / HYPOTHESIS
 BY DEFINITION, THE FIRST TWO FIBONACCI NUMBERS ARE 0 AND 1, AND EACH
SUBSEQUENT NUMBER IS THE SUM OF THE PREVIOUS TWO.

7. BACKGROUND INFORMATION ...:


 They should have the idea of fibonacci sequence

8. PROCEDURE / PROGRAMME / ACTIVITY ...:

import java.io.*; //importing io package

import java.lang.*; //importing Lang package


class A
{
int a,b,c;
A( int f1,int f2 )
{
a=f1;
b=f2;
Page No.: 3/55
Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
} //End of constructor A
void Feb()
{
c=a+b;
System.out.print("\t" + c);

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


a=b;
b=c;
}//End of method Feb
} //End of class A

class Febinocci
{
public static void main(String args[])throws IOException
{
int n,f3, i;
A a=new A(0,1);
System.out.println("Enter how many numbers you want in febinoci series");
BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
n=Integer.parseInt(stdin.readLine());
System.out.println("The febinocci series is as follows");
System.out.print("\t" + 0);
System.out.print("\t" + 1);
for(i=0;i<(n-2);i++)
{
a.Feb();
} //End of for loop
} //End of main
} //END OF CLASS FEBINOCCI

9. BLOCK / CIRCUIT / MODEL / REACTION DIAGRAM ...:

10. OBSERVATION TABLE / LOOKUP TABLE / TRUTH TABLE ...:

11. FORMULA / CALCULATIONS ...:

 F_n=F_(n-1)+F_(n-2)

12. GRAPHS / OUTPUTS ...:

0 1 1 2 3 5 8 13.......

13. RESULTS & ANALYSIS ...:

Page No.: 4/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
Enter how many numbers you want in febinoci series 3

The febinocci series is as follows 0 1 1


Enter how many numbers you want in febinoci series 6
The febinocci series is as follows 0 11 2 3 5
Enter how many numbers you want in febinoci series 10

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


The febinocci series is as follows 0 1 1 2 3 5 8 13 21 34

14. OUTCOME & CONCLUSIONS ...:

15. REMARKS
 -
 -
 -

FACULTY SIGNATURE

Page No.: 5/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


1. EXPERIMENT NO: Date Planned Date Conducted Marks
II 17/12/12
20/12/12

2. TITLE:
 Program to Find The Primary Numbers

3. LEARNING OBJECTIVES:
 They can able to write the java program on primari numbers

4. AIM:
 Write a java program to find the given primary numbers.

5. MATERIAL / EQUIPMENT REQUIRE ...:


 A good configured PC
 JDK software

6. THEORY / HYPOTHESIS
 A PRIME NUMBER (OR A PRIME) IS A NATURAL NUMBER THAT HAS EXACTLY TWO DISTINCT
NATURAL NUMBER DIVISORS: 1 AND ITSELF

7. BACKGROUND INFORMATION ...:


 Students should know what is a primary number and what are the primary numbers

8. PROCEDURE / PROGRAMME / ACTIVITY ...:

import java.io.*;

class prime
{
public static void main(String s[]) throws IOException
{
int i,j,c,n;
BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter Positive value :");
n=Integer.parseInt(stdin.readLine());
for (i=1;i<=n;i++)
{

Page No.: 6/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
for(j=1,c=0;j<=i;j++)
{
if (i%j==0)
c=c+1;
}

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


if(c==2)
System.out.println(i);
}
}
}

9. BLOCK / CIRCUIT / MODEL / REACTION DIAGRAM ...:

10. OBSERVATION TABLE / LOOKUP TABLE / TRUTH TABLE ...:

11. FORMULA / CALCULATIONS ...:


p=7d-4
p=prime number to be find
d=any odd number

12. GRAPHS / OUTPUTS ...:


3,5,7,11,13.....

13. RESULTS & ANALYSIS ...:


Enter positive value:

10
2
3
5
7

14. OUTCOME & CONCLUSIONS ...:

15. REMARKS

FACULTY SIGNATURE

Page No.: 7/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


1. EXPERIMENT NO: Date Planned Date Conducted Marks
III 24/12/12
27/12/12

2. TITLE:
Program To generate the Quadratic equation

3. LEARNING OBJECTIVES:
students can able to write the java program on quadratic equation

4. AIM:
Write a java program to generate the quadratic equation.

5. MATERIAL / EQUIPMENT REQUIRE ...:


 A good configured PC
 JDK software

6. THEORY / HYPOTHESIS ...:


In mathematics, a quadratic equation is a polynomial equation of the second degree.

7. BACKGROUND INFORMATION ...:


They should know what is a quadratic equation

8. PROCEDURE / PROGRAMME / ACTIVITY ...:


import java.io.*;

import java.math.*;
class quadratic
{
public static void main(String s[]) throws IOException
{
int a,b,c,d;
double r1,r2;
BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter value of a:");
a=Integer.parseInt(stdin.readLine());
System.out.println("Enter value of b:");
b=Integer.parseInt(stdin.readLine());
System.out.println("Enter value of c:");
Page No.: 8/55
Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
c=Integer.parseInt(stdin.readLine());
d=b*b-4*a*c;
if(d==0)
{
System.out.println("Roots are Equalent");

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


r1=-b/(2*a);
r2=-b/(2*a);
System.out.println("Root1 = "+r1);
System.out.println("Root2 = "+r2);
}
else if (d>0)
{
System.out.println("Roots are Real");
r1=(-b+Math.sqrt(d))/(2*a);
r2=(-b-Math.sqrt(d))/(2*a);
System.out.println("Root1 = "+r1);
System.out.println("Root2 = "+r2);
}
else
System.out.println("Roots are Imaginary");
}

9. BLOCK / CIRCUIT / MODEL / REACTION DIAGRAM ...:

10. OBSERVATION TABLE / LOOKUP TABLE / TRUTH TABLE ...:

11. FORMULA / CALCULATIONS ...:


ax2+bx+c=0
x=-b+
x=-b-

12. GRAPHS / OUTPUTS ...:


Enter value of a:1
Enter value of b:2
Enter value of c:1
Roots are Equivalent
Enter value of a:2
Enter value of b:3
Enter value of c:2
Roots are Imaginary

13. RESULTS & ANALYSIS ...:


Enter value of a:1

Page No.: 9/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
Enter value of b:2
Enter value of c:1
Roots are Equivalent
Enter value of a:2
Enter value of b:3
Enter value of c:2
Roots are Imaginary

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


14. OUTCOME & CONCLUSIONS ...:

15. REMARKS

FACULTY SIGNATURE

1. EXPERIMENT NO: Date Planned Date Conducted Marks


IV 24/12/12
27/12/12

2. TITLE:
Program to implement Mouse Listener (Mouse Events)

3. LEARNING OBJECTIVES:
They can able to write the java program on mouse listeners

4. AIM:
Write a java program to implement the APPLET PACKAGES, draw Mouse event handler programs.

5. MATERIAL / EQUIPMENT REQUIRE ...:


 A good configured PC
 JDK software

6. THEORY / HYPOTHESIS ...:


Mouse events notify when the user uses the mouse (or similar input device) to interact with a
component. Mouse events occur when the cursor enters or exits a component's onscreen area
and when the user presses or releases one of the mouse buttons.

7. BACKGROUND INFORMATION ...:


To do the mouse events they should know the concept of applet

8. PROCEDURE / PROGRAMME / ACTIVITY ...:


import java.awt.*;

import java.applet.*;
import java.awt.event.*;
/*<applet code="MouseDemo" width=300 height=300>
</applet>*/
public class MouseDemo extends Applet implements MouseListener,MouseMotionListener

Page No.: 10/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
{
int mx=0;
int my=0;
String msg="";
public void init()

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


{
addMouseListener(this);
addMouseMotionListener(this);
}
public void mouseClicked(MouseEvent me)
{
mx=20;
my=40;
msg="Mouse Clicked";
repaint();
}
public void mousePressed(MouseEvent me)
{
mx=30;
my=60;
msg="Mouse Pressed";
repaint();
}
public void mouseReleased(MouseEvent me)
{
mx=30;
my=60;
msg="Mouse Released";
repaint();

}
public void mouseEntered(MouseEvent me)
{
mx=40;
my=80;
msg="Mouse Entered";
repaint();
}
public void mouseExited(MouseEvent me)
{
mx=40;
my=80;

Page No.: 11/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
msg="Mouse Exited";
repaint();
}
public void mouseDragged(MouseEvent me)
{

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


mx=me.getX();
my=me.getY();
showStatus("Currently mouse dragged"+mx+" "+my);
repaint();
}
public void mouseMoved(MouseEvent me)
{
mx=me.getX();
my=me.getY();
showStatus("Currently mouse is at"+mx+" "+my);
repaint();
}
public void paint(Graphics g)
{
g.drawString("Handling Mouse Events",30,20);
g.drawString(msg,60,40);
}
}

9. Block / Circuit / model / reaction Diagram ...:

10. OBSERVATION TABLE / LOOKUP TABLE / TRUTH TABLE ...:

11. FORMULA / CALCULATIONS ...:

12. GRAPHS / OUTPUTS ...:

Page No.: 12/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


13. RESULTS & ANALYSIS ...:

14. OUTCOME & CONCLUSIONS ...:

15. REMARKS

FACULTY SIGNATURE

Page No.: 13/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
1. EXPERIMENT NO: Date Planned Date Conducted Marks
V 31/12/12
03/01/13

2. TITLE:
Program to find multiplication of two matrices

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


3. LEARNING OBJECTIVES:
They can able to write the java program on multiplication of two matrices

4. AIM:
Write a Program To find the product of matrices

5. MATERIAL / EQUIPMENT REQUIRE ...:


 A good configured PC
 JDK software

6. THEORY / HYPOTHESIS ...:


They should know what is 3x3 matrix and how to multiply two matrices

7. BACKGROUND INFORMATION ...:


They should know what is 3x3 matrix and how to multiply two matrices

8. PROCEDURE / PROGRAMME / ACTIVITY ...:


import java.io.*; //Importing io package
class Matrix
{
public static void main(String args[]) throws IOException
{
int a[][]=new int[3][3];
int b[][]=new int[3][3];
int p[][]=new int[3][3];
int i,j;
BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the elements of 1st matrix");
for( i=0;i<3;i++) //Reading the elements of first matrix
{
for(j=0;j<3;j++)
{
a[i][j]=Integer.parseInt(stdin.readLine());
}
}
System.out.println("Enter the elements of the 2nd matrix");
for(i=0;i<3;i++) //Reading the elements of second matrix
{
for(j=0;j<3;j++)
{
b[i][j]=Integer.parseInt(stdin.readLine());
}
}
}
System.out.println("The productof the matrices is");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
p[i][j]=0;

Page No.: 14/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
for(int k=0;k<3;k++)
{
p[i][j]=p[i][j]+a[i][k]*b[k][j];
}
System.out.print(" "+p[i][j]);
}
System.out.println();

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


}
}
}

9. BLOCK / CIRCUIT / MODEL / REACTION DIAGRAM ...:

10. OBSERVATION TABLE / LOOKUP TABLE / TRUTH TABLE ...:

11. FORMULA / CALCULATIONS ...:

12. GRAPHS / OUTPUTS ...:


Enter the elements of 1st matrix 1 2 3 4 1 2 3 4 1
Enter the elements of 2nd matrix 2 3 4 5 6 1 2 3 4
The productof the matrices is
18 24 18
17 24 25
28 36 20

13. RESULTS & ANALYSIS ...:

14. OUTCOME & CONCLUSIONS ...:

15. REMARKS

FACULTY SIGNATURE

1. EXPERIMENT NO: Date Planned Date Conducted Marks


VI 31/12/12
03/01/13

Page No.: 15/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
2. TITLE:
program that display each integer and sum of all integers using stringtokenizer

3. LEARNING OBJECTIVES:
student will learn the concept of string tokenizers

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


4. AIM:
Write a program that display each integer and sum of all integers using stringtokenizer

5. MATERIAL / EQUIPMENT REQUIRE ...:


 A good configured PC
 JDK software

6. THEORY / HYPOTHESIS ...:


The processing of text often consists of parsing a formatted input string. Parsing is the division of
text into a set of discrete parts, or tokens, which in a certain sequence can convey a semantic
meaning. The StringTokenizer class provides the first step in this parsing process, often called
the lexer (lexical analyzer) or scanner. StringTokenizer implements the Enumeration
interface. Therefore, given an input string, you can enumerate the individual tokens contained in
it using StringTokenizer.

7. BACKGROUND INFORMATION ...:


students should know what is string tokenizer

8. PROCEDURE / PROGRAMME / ACTIVITY ...:


import java.util.*;
class Stringtoken
{
public static void main(String arg[])
{
int sum=0;
StringTokenizer sto=new StringTokenizer(arg[0],":");
System.out.println(sto.countTokens());
while(sto.hasMoreTokens())
{
int a=Integer.parseInt(sto.nextToken());
sum=sum+a;
System.out.println(a);
}
System.out.println("sum= "+sum);
}
}

9. BLOCK / CIRCUIT / MODEL / REACTION DIAGRAM ...:

10. OBSERVATION TABLE / LOOKUP TABLE / TRUTH TABLE ...:

11. FORMULA / CALCULATIONS ...:

12. GRAPHS / OUTPUTS ...:

Page No.: 16/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy

13. RESULTS & ANALYSIS ...:


1
2
3
4

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


sum=10

14. OUTCOME & CONCLUSIONS ...:

15. REMARKS

FACULTY SIGNATURE

1. EXPERIMENT NO: Date Planned Date Conducted Marks


VII 07/01/13
10/01/13

2. TITLE:
Program to draw Lines, Rectangles, Rounded Rectangles, filled Polygons and Ovals

3. LEARNING OBJECTIVES:
They will learn the concept of applet

4. AIM:
Write a java program to implement the APPLET PACKAGES, draw Lines, Rectangles, Rounded
Rectangles, filled Polygons programs.

5. MATERIAL / EQUIPMENT REQUIRE ...:


 A good configured PC
 JDK software

6. THEORY / HYPOTHESIS ...:


An applet is any small application that performs one specific task, sometimes running within the
context of a larger program.

7. BACKGROUND INFORMATION ...:


Should have the concept of applet

8. PROCEDURE / PROGRAMME / ACTIVITY ...:


import java.awt.*;

Page No.: 17/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
import java.applet.*;
import java.awt.event.*;
/*<applet code="ShapeDemo" width=300 height=300>
</applet*/
public class ShapeDemo extends Applet
{
public void paint(Graphics g)

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


{
setLayout(new FlowLayout());
g.drawLine(10,20,50,20);
g.drawRect(20,30,30,30);
g.setColor(Color.RED);
g.fillRect(20,30,30,30);
g.drawRoundRect(20,70,50,70,15,15);
g.setColor(Color.GREEN);
g.fillRoundRect(20,70,50,70,15,15);
g.drawOval(20,150,50,50);
g.setColor(Color.BLUE);
g.fillOval(20,150,50,50);
}
}

9. BLOCK / CIRCUIT / MODEL / REACTION DIAGRAM ...:

10. OBSERVATION TABLE / LOOKUP TABLE / TRUTH TABLE ...:

11. FORMULA / CALCULATIONS ...:

12. GRAPHS / OUTPUTS ...:

13. RESULTS & ANALYSIS ...:

Page No.: 18/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA

14. OUTCOME & CONCLUSIONS ...:

Page No.: 19/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
15. REMARKS

FACULTY SIGNATURE

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


1. EXPERIMENT NO: Date Planned Date Conducted Marks
VIII 07/01/13
10/01/13

2. TITLE:
program to implement the palindrome of a given string

3. LEARNING OBJECTIVES:
They can able to write the java program on palindrome of a given string

4. AIM:
write a java program that checks a given string is a palindrome or not

5. MATERIAL / EQUIPMENT REQUIRE ...:


 A good configured PC
 JDK software

6. THEORY / HYPOTHESIS ...:


A palindrome is a word or sentence that is the same spelled forward or backward. For example,
take a look at the following sentence: "Madam, I'm Adam". If you omit the punctuation, you can
see that the letters spell the same thing forward and backward

7. BACKGROUND INFORMATION ...:


students should know the concept of palindrome.

8. PROCEDURE / PROGRAMME / ACTIVITY ...:


class palindrome
{
public static void main(String[] args)
{
StringBuffer s1=new StringBuffer(args[0]);
StringBuffer s2=new StringBuffer(s1);
s1.reverse();
System.out.println(“Given String is:”+s2);
System.out.println(“Reverse String is”+s1);
if(String.valueOf(s1).compareTo(String.valueOf(s2))==0)
System.out.println(“Palindrome”);
else
System.out.println(“Not Palindrome”);

Page No.: 20/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
}
}

9. BLOCK / CIRCUIT / MODEL / REACTION DIAGRAM ...:

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


10. OBSERVATION TABLE / LOOKUP TABLE / TRUTH TABLE ...:

11. FORMULA / CALCULATIONS ...:

12. GRAPHS / OUTPUTS ...:


Input:madam
output:madam

13. RESULTS & ANALYSIS ...:


java palindrome madam
Given String is:madam
Reverse String is madam
Palindrome
Java palindrome harish
Given String is:harish
Reverse String is hsirah
Not Palindrome

14. OUTCOME & CONCLUSIONS ...:

15. REMARKS

FACULTY SIGNATURE

Page No.: 21/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy

1. EXPERIMENT NO: Date Planned Date Conducted Marks


IX 14/01/13
17/01/13

2. TITLE:

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


Program to implement sorting of given list of names in ascending order

3. LEARNING OBJECTIVES:
They can able to write the java program on sorting of names in ascending order

4. AIM:
Write a java program for sorting a given list of names in ascending order

5. MATERIAL / EQUIPMENT REQUIRE ...:


 A good configured PC
 JDK software

6. THEORY / HYPOTHESIS ...:


Sorting is the process of arranging data into meaningful order so that you can analyze it more
effectively. For example, you might want to order sales data by calendar month so that you can
produce a graph of sales performance

7. BACKGROUND INFORMATION ...:


Students should know what is sorting and what are the different sorting techniques

8. PROCEDURE / PROGRAMME / ACTIVITY ...:


class sorting
{
public static void main(String[] input)
{
int k=input.length;
String temp=new String();
String names[]=new String[k+1];
for(int i=0;i<k;i++)
{
names[i]=input[i];
}
for(int i=0;i<k;i++)
for(int j=i+1;j<k;j++)
{
if(names[i].compareTo(names[j])<0)
{
temp=names[i];
names[i]=names[j];
names[j]=temp;
}
}
System.out.println(“Sorted order is”);
for(int i=0;i<k;i++)
Page No.: 22/55
Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
{
System.out.println(names[i]);
}
}
}

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


9. BLOCK / CIRCUIT / MODEL / REACTION DIAGRAM ...:

10. OBSERVATION TABLE / LOOKUP TABLE / TRUTH TABLE ...:

11. FORMULA / CALCULATIONS ...:

12. GRAPHS / OUTPUTS ...:


Java sorting Harish Ramesh Mahesh Rakesh
Sorted order is
Ramesh
Rakesh
Mahesh
Harish

13. RESULTS & ANALYSIS ...:


Java sorting Harish Ramesh Mahesh Rakesh
Sorted order is
Ramesh
Rakesh
Mahesh
Harish

Java sorting sai hari teja ravi sandeep


Sorted order is
teja
sandeep
sai
ravi
hari

14. OUTCOME & CONCLUSIONS ...:

Page No.: 23/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


15. REMARKS

FACULTY SIGNATURE

1. EXPERIMENT NO: Date Planned Date Conducted Marks


X 14/01/13
17/01/13

2. TITLE:
Program to make frequency count of words in a given text

3. LEARNING OBJECTIVES:
students can write the program on to counting the no of words in the given text.

4. AIM:
Write a java program to make frequency count of words in a given text

5. MATERIAL / EQUIPMENT REQUIRE ...:


 A good configured PC
 JDK software

6. THEORY / HYPOTHESIS ...:


The String class represents character strings. All string literals in Java programs, such as "abc",
are implemented as instances of this class

7. BACKGROUND INFORMATION ...:


students should know the concept of string

8. PROCEDURE / PROGRAMME / ACTIVITY ...:


import java.util.*;
import java.lang.*;
import java.io.*;
class Fre
{
public static void main(String[ ] args) throws IOException
{
DataInputStream dis=new DataInputStream(System.in);
String str=dis.readLine();
String temp;
StringTokenizer st=new StringTokenizer(str);
int n=st.countTokens( );
String a[ ]=new String[n];

Page No.: 24/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
int i=0,count=0;
while(st.hasMoreTokens())
{
a[i]=st.nextToken();
i++;
}
for(int x=1;x<n;x++)

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


{
for(int y=0;y<n-x;y++)
{
if(a[y].compareTo(a[y+1])>0)
{
temp=a[y];
a[y]=a[y+1];
a[y+1]=temp;
}
}
}
System.out.println("the sorted string are:");
for(i=0;i<n;i++)
{
System.out.println(a[i]+" ");
}
System.out.println();
for(i=0;i<n;i++)
{count=1;
if(i<n-1)
{
while(a[i].compareTo(a[i+1])==0)
{
count++;
i++;
if(i>=n-1)
{
System.out.println(a[i]+" "+count);
System.exit(0);
}
}
}
System.out.println(a[i]+" "+count);
}
}
}

9. BLOCK / CIRCUIT / MODEL / REACTION DIAGRAM ...:

10. OBSERVATION TABLE / LOOKUP TABLE / TRUTH TABLE ...:

11. FORMULA / CALCULATIONS ...:

12. GRAPHS / OUTPUTS ...:

13. RESULTS & ANALYSIS ...:


ree sach sai ree sach

Page No.: 25/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
the sorted list are:
ree
ree
sach
sach
sai
ree 2

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


sach 2
sai 1

14. OUTCOME & CONCLUSIONS ...:

15. REMARKS

FACULTY SIGNATURE

1. EXPERIMENT NO: Date Planned Date Conducted Marks


XI 21/01/13
24/01/13

2. TITLE:
Java program to display the information of a file

3. LEARNING OBJECTIVES:
students can able to write the program on display the information of file in java language

4. AIM:
Write a Program That reads on a file and display the information that whether the file exists or
not, to display the information about the file and find the type of file whether readable,
writable and the length of bytes

5. MATERIAL / EQUIPMENT REQUIRE ...:


 A good configured PC

Page No.: 26/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
 JDK software

6. THEORY / HYPOTHESIS ...:


A collection of data or information that has a name, called the filename. Almost all information
stored in a computer must be in a file. There are many different types of files: data files, text files
, program files, directory files, and so on. Different types of files store different types of

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


information. For example, program files store programs, whereas text files store text.

7. BACKGROUND INFORMATION ...:


They should know concept of file. And the difference between file and stream

8. PROCEDURE / PROGRAMME / ACTIVITY ...:


import java.util.Scanner;
import java.io.File;
class FileDemo
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
String s=input.nextLine();
File f1=new File(s);
System.out.println("File Name:"+f1.getName());
System.out.println("Path:"+f1.getPath());
System.out.println("Abs Path:"+f1.getAbsolutePath());
System.out.println("Parent:"+f1.getParent());
System.out.println("This file is:"+(f1.exists()?"Exists":"Does not exists"));
System.out.println("Is file:"+f1.isFile());
System.out.println("Is Directory:"+f1.isDirectory());
System.out.println("Is Readable:"+f1.canRead());
System.out.println("IS Writable:"+f1.canWrite());
System.out.println("Is Absolute:"+f1.isAbsolute());
System.out.println("File Last Modified:"+f1.lastModified());
System.out.println("File Size:"+f1.length()+"bytes");
System.out.println("Is Hidden:"+f1.isHidden());
}
}

9. BLOCK / CIRCUIT / MODEL / REACTION DIAGRAM ...:

10. OBSERVATION TABLE / LOOKUP TABLE / TRUTH TABLE ...:

11. FORMULA / CALCULATIONS ...:

12. GRAPHS / OUTPUTS ...:

13. RESULTS & ANALYSIS ...:


Fibonacci.java
File Name:Fibonacci.java
Path: Fibonacci.java
Abs Path: c:\sameer\Fibonacci.java
Parent: Null
Page No.: 27/55
Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
This file is:Exists
Is file:true
Is Directory:false
Is Readable:true
Is Writable:true
Is Absolute:false

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


File Last Modified:1206324301937
File Size: 406 bytes
Is Hidden:false

14. OUTCOME & CONCLUSIONS ...:

15. REMARKS

FACULTY SIGNATURE

1. EXPERIMENT NO: Date Planned Date Conducted Marks


XII 21/01/13
24/01/13
2. TITLE:
Program to implement read the file and display the file

3. LEARNING OBJECTIVES:
They can able to write the java program on read the file and display the file

4. AIM:
Write a Program That reads a file and displays the file on the screen within line number before
each line

5. MATERIAL / EQUIPMENT REQUIRE ...:


 A good configured PC
 JDK software

6. THEORY / HYPOTHESIS ...:


A collection of data or information that has a name, called the filename. Almost all information
stored in a computer must be in a file. There are many different types of files: data files, text files
, program files, directory files, and so on. Different types of files store different types of
information. For example, program files store programs, whereas text files store text.

Page No.: 28/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy

7. BACKGROUND INFORMATION ...:


They should have the idea of file and stream

8. PROCEDURE / PROGRAMME / ACTIVITY ...:


import java.io.*;

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


class linenum
{
public static void main(String[] args)throws IOException
{
FileInputStream fil;
LineNumberInputStream line;
int i;
try
{
fil=new FileInputStream(args[0]);
line=new LineNumberInputStream(fil);
}
catch(FileNotFoundException e)
{
System.out.println("No such file found");
return;
}
do
{
i=line.read();
if(i=='\n')
{
System.out.println();
System.out.print(line.getLineNumber()+" ");
}
else
System.out.print((char)i);
}while(i!=-1);
fil.close();
line.close();
}
}

9. BLOCK / CIRCUIT / MODEL / REACTION DIAGRAM ...:

10. OBSERVATION TABLE / LOOKUP TABLE / TRUTH TABLE ...:

11. FORMULA / CALCULATIONS ...:

12. GRAPHS / OUTPUTS ...:


class Demo
1{
2 public static void main(java Demo beta gamma delta)
3{
4 int n = 1 ;
5 System.out.println(“The word is ” + args[ n ] );
6}

Page No.: 29/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
7}
8?

13. RESULTS & ANALYSIS ...:


Demo.java

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


class Demo
1{
2 public static void main(java Demo beta gamma delta)
3{
4 int n = 1 ;
5 System.out.println(“The word is ” + args[ n ] );
6}
7}
8?

14. OUTCOME & CONCLUSIONS ...:

15. REMARKS

FACULTY SIGNATURE
1. EXPERIMENT NO: Date Planned Date Conducted Marks
XIII 28/01/13
31/01/13

2. TITLE:
Program to print number of characters, words, lines in the file

3. LEARNING OBJECTIVES:
They can able to write the program on number of characters, words, lines in the file

4. AIM:
Write a Program That prints a number of characters ,words,lines in that file

5. MATERIAL / EQUIPMENT REQUIRE ...:


 A good configured PC
 JDK software

6. THEORY / HYPOTHESIS ...:


A collection of data or information that has a name, called the filename. Almost all information
stored in a computer must be in a file. There are many different types of files: data files, text files
, program files, directory files, and so on. Different types of files store different types of
information. For example, program files store programs, whereas text files store text.

7. BACKGROUND INFORMATION ...:


They should have the concept of file

8. PROCEDURE / PROGRAMME / ACTIVITY ...:

Page No.: 30/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
import java.io.*;
class wordcount
{
public static int words=0;
public static int lines=0;
public static int chars=0;
public static void wc(InputStreamReader isr)throws IOException

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


{
int c=0;
boolean lastwhite=true;
while((c=isr.read())!=-1)
{
chars++;
if(c=='\n')
lines++;
if(c=='\t' || c==' ' || c=='\n')
++words;
if(chars!=0)
++chars;
}
}
public static void main(String[] args)
{
FileReader fr;
try
{
if(args.length==0)
{
wc(new InputStreamReader(System.in));
}
else
{
for(int i=0;i<args.length;i++)
{
fr=new FileReader(args[i]);
wc(fr);
}
}

}
catch(IOException ie)
{
return;
}
System.out.println(lines+" "+words+" "+chars);
}
}

9. BLOCK / CIRCUIT / MODEL / REACTION DIAGRAM ...:

10. OBSERVATION TABLE / LOOKUP TABLE / TRUTH TABLE ...:

11. FORMULA / CALCULATIONS ...:

12. GRAPHS / OUTPUTS ...:

Page No.: 31/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy

13. RESULTS & ANALYSIS ...:


This is II CSE
1 4 32
Draw the frequency response
1 4 58

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


14. OUTCOME & CONCLUSIONS ...:

15. REMARKS

FACULTY SIGNATURE

1. EXPERIMENT NO: Date Planned Date Conducted Marks


XIV 04/02/13
07/02/13

2. TITLE:
Program to implement stack ADT

3. LEARNING OBJECTIVES:
students can able to write the java program on stack ADT

4. AIM:
Write a Program That
implements a stack ADT

5. MATERIAL / EQUIPMENT REQUIRE ...:


 A good configured PC
 JDK software

6. THEORY / HYPOTHESIS ...:


In computer science, a stack is a last in, first out (LIFO) abstract data type and data structure. A
stack can have any abstract data type as an element, but is characterized by only two
fundamental operations: push and pop. The push operation adds to the top of the list, hiding any
items already on the stack, or initializing the stack if it is empty. The pop operation removes an
item from the top of the list, and returns this value to the caller

7. BACKGROUND INFORMATION ...:


They should know what is stack and which technique it follows

8. PROCEDURE / PROGRAMME / ACTIVITY ...:


import java.util.Scanner;
class stack<E>
{
Page No.: 32/55
Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
private final int size;
private int top;
private E[] elements;
public stack()
{
this(10);
}

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


public stack(int s)
{
size=s>0?s:10;
top=-1;
elements=(E[])new Object[size];
}
public void push(E x)
{
if(top==size-1)
System.out.println("Overflow");
elements[++top]=x;
}
public E pop()
{
if(top==-1)
System.out.println("Underflow");
return elements[top--];
}
public void display()
{
if(top==-1)
System.out.println("Stack is empty");
else
{
for(int i=0;i<top;i++)
System.out.println(elements[i]);
}
}
}

public class stacktest


{
public static void main(String[] args)
{
int ch,ch1;
stack<Double>d_stack;
d_stack=new stack<Double>(5);
Scanner input=new Scanner(System.in);
do
{
System.out.println("Menu is as follows:");
System.out.println("1.Push\n2.Pop\n3.Display\n4.Exit");
System.out.println("Enter your choice:");
ch=input.nextInt();
switch(ch)
{
case 1: System.out.println("Enter element to push:");
double item=input.nextInt();
d_stack.push(item);
break;
case 2: double item1=d_stack.pop();
System.out.println("Popped
item:"+item1);
break;
case 3: d_stack.display();
break;
Page No.: 33/55
Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
default: break;
}
}while(ch!=4);
}
}

9. BLOCK / CIRCUIT / MODEL / REACTION DIAGRAM ...:

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


10. OBSERVATION TABLE / LOOKUP TABLE / TRUTH TABLE ...:

11. FORMULA / CALCULATIONS ...:

12. GRAPHS / OUTPUTS ...:

13. RESULTS & ANALYSIS ...:

14. OUTCOME & CONCLUSIONS ...:

15. REMARKS

FACULTY SIGNATURE

Page No.: 34/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


1. EXPERIMENT NO: Date Planned Date Conducted Marks
XV 18/02/13
21/02/13

2. TITLE:
Program to implement infix expression into postfix expression

3. LEARNING OBJECTIVES:
students can able to write the java program on conversion of infix expression into postfix
expression

4. AIM:
Write a JAVA program to implement infix expression into postfix expression

5. MATERIAL / EQUIPMENT REQUIRE ...:


 A good configured PC
 JDK software

6. THEORY / HYPOTHESIS ...:


There are three different ways in which an expression like a+b can be represented.
Prefix (Polish)
+ab
Postfix (Suffix or reverse polish)
ab+
Infix
a+b
Note that an infix expression can have parathesis, but postfix and prefix expressions are
paranthesis free expressions.

7. BACKGROUND INFORMATION ...:


They should know what is infix expression and what is postfix expression

8. PROCEDURE / PROGRAMME / ACTIVITY ...:


import java.io.*;
class stack
{
char stack1[]=new char[20];
int top;

Page No.: 35/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
void push(char ch)
{
top++;
stack1[top]=ch;
}
char pop()
{

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


char ch;
ch=stack1[top];
top--;
return ch;
}
int pre(char ch)
{
switch(ch)
{
case '-':return 1;
case '+':return 1;
case '*':return 2;
case '/':return 2;
}
return 0;
}
boolean operator(char ch)
{
if(ch=='/'||ch=='*'||ch=='+'||ch=='-')
return true;
else
return false;
}
boolean isAlpha(char ch)
{
if(ch>='a'&&ch<='z'||ch>='0'&&ch=='9')
return true;
else
return false;
}
void postfix(String str)
{
char output[]=new char[str.length()];
char ch;
int p=0,i;
for(i=0;i<str.length();i++)
{
ch=str.charAt(i);
if(ch=='(')
{
push(ch);
}
else if(isAlpha(ch))
{
output[p++]=ch;
}
else if(operator(ch))
{
if(stack1[top]==0||(pre(ch)>pre(stack1[top]))||
stack1[top]=='(')
{
push(ch);
}
}
else if(pre(ch)<=pre(stack1[top]))
{
Page No.: 36/55
Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
output[p++]=pop();
push(ch);
}
else if(ch=='(')
{
while((ch=pop())!='(')
{

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


output[p++]=ch;
}
}
}
while(top!=0)
{
output[p++]=pop();
}
for(int j=0;j<str.length();j++)
{
System.out.print(output[j]);
}
}
}
class intopost
{
public static void main(String[] args)throws Exception
{
String s;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
stack b=new stack();
System.out.println("Enter input string");
s=br.readLine();
System.out.println("Input String:"+s);
System.out.println("Output String:");
b.postfix(s);
}
}

9. BLOCK / CIRCUIT / MODEL / REACTION DIAGRAM ...:

10. OBSERVATION TABLE / LOOKUP TABLE / TRUTH TABLE ...:

11. FORMULA / CALCULATIONS ...:

12. GRAPHS / OUTPUTS ...:

13. RESULTS & ANALYSIS ...:


Enter input string
a+b*c
Input String:a+b*c
Output String:
abc*+
Enter input string
a+(b*c)/d
Input String:a+(b*c)/d
Page No.: 37/55
Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
Output String:
abc*d/)(+

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


14. OUTCOME & CONCLUSIONS ...:

15. REMARKS

FACULTY SIGNATURE

Page No.: 38/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy

1. EXPERIMENT NO: Date Planned Date Conducted Marks


XVI 25/02/13

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


28/02/13

2. TITLE:
Develop an applet that receives an integer in one text field, and computes as factorial
value and returns it in another text field,when the button named “Compute” is clicked

3. LEARNING OBJECTIVES:
students will learn applet concepts.

4. AIM:
Develop an applet that receives an integer in one text field, and computes as factorial
value and returns it in another text field,when the button named “Compute” is clicked

5. MATERIAL / EQUIPMENT REQUIRE ...:


 A good configured PC
 JDK software

6. THEORY / HYPOTHESIS ...:


Applet is java program that can be embedded into HTML pages. Java applets runs on the java
enables web browsers such as mozila and internet explorer. Applet is designed to run remotely on
the client browser, so there are some restrictions on it. Applet can't access system resources on
the local computer. Applets are used to make the web site more dynamic and entertaining

7. BACKGROUND INFORMATION ...:


students should know what is applet

8. PROCEDURE / PROGRAMME / ACTIVITY ...:


import java.io.*;
import java.awt.*;
import java.applet.Applet;
/*<applet code="appletTest.class" height=100 width=500></applet>*/
public class appletTest extends Applet
{
public void paint(Graphics g)
{
g.drawString("This is IT IInd Year IInd sem",50,60);
setForeground(Color.blue);
}
}

9. BLOCK / CIRCUIT / MODEL / REACTION DIAGRAM ...:

10. OBSERVATION TABLE / LOOKUP TABLE / TRUTH TABLE ...:

11. FORMULA / CALCULATIONS ...:


Page No.: 39/55
Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy

12. GRAPHS / OUTPUTS ...:

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


13. RESULTS & ANALYSIS ...:
this is II year II sem

14. OUTCOME & CONCLUSIONS ...:

15. REMARKS

FACULTY SIGNATURE

1. EXPERIMENT NO: Date Planned Date Conducted Marks


Page No.: 40/55
Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
XVII 04/03/13
07/03/13

2. TITLE:
Program to display simple message using applet

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


3. LEARNING OBJECTIVES:
They can able to write the program on displaying a message using applet

4. AIM:
Write an applet that displays a simple message

5. MATERIAL / EQUIPMENT REQUIRE ...:


 A good configured PC
 JDK software

6. THEORY / HYPOTHESIS ...:


They should know what is mean by applet

7. BACKGROUND INFORMATION ...:

8. PROCEDURE / PROGRAMME / ACTIVITY ...:


import java.awt.*;
import java.awt.event.*;
import java.applet.*;

/*
<applet code="Cal" width=300 height=300>
</applet>
*/

public class Cal extends Applet


implements ActionListener
{
String msg=" ";
int v1,v2,result;
TextField t1;
Button b[]=new Button[10];
Button add,sub,mul,div,clear,mod,EQ;
char OP;
public void init()
{
Color k=new Color(120,89,90);
setBackground(k);
t1=new TextField(10);
GridLayout gl=new GridLayout(4,5);
setLayout(gl);
for(int i=0;i<10;i++)
{
b[i]=new Button(""+i);
}
add=new Button("add");
sub=new Button("sub");
mul=new Button("mul");
div=new Button("div");

Page No.: 41/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
mod=new Button("mod");
clear=new Button("clear");
EQ=new Button("EQ");
t1.addActionListener(this);
add(t1);
for(int i=0;i<10;i++)
{

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


add(b[i]);
}
add(add);
add(sub);
add(mul);
add(div);
add(mod);
add(clear);
add(EQ);
for(int i=0;i<10;i++)
{
b[i].addActionListener(this);
}
add.addActionListener(this);
sub.addActionListener(this);
mul.addActionListener(this);
div.addActionListener(this);
mod.addActionListener(this);
clear.addActionListener(this);
EQ.addActionListener(this);
}

public void actionPerformed(ActionEvent ae)


{
String str=ae.getActionCommand();
char ch=str.charAt(0);
if ( Character.isDigit(ch))
t1.setText(t1.getText()+str);
else
if(str.equals("add"))
{
v1=Integer.parseInt(t1.getText());
OP='+';
t1.setText("");
}
else if(str.equals("sub"))
{
v1=Integer.parseInt(t1.getText());
OP='-';
t1.setText("");
}
else if(str.equals("mul"))
{
v1=Integer.parseInt(t1.getText());
OP='*';
t1.setText("");
}
else if(str.equals("div"))
{
v1=Integer.parseInt(t1.getText());
OP='/';
t1.setText("");
}
else if(str.equals("mod"))
{
v1=Integer.parseInt(t1.getText());
Page No.: 42/55
Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
OP='%';
t1.setText("");
}
if(str.equals("EQ"))
{
v2=Integer.parseInt(t1.getText());
if(OP=='+')

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


result=v1+v2;
else if(OP=='-')
result=v1-v2;
else if(OP=='*')
result=v1*v2;
else if(OP=='/')
result=v1/v2;
else if(OP=='%')
result=v1%v2;
t1.setText(""+result);
}
if(str.equals("clear"))
{
t1.setText("");
}
}
}

9. BLOCK / CIRCUIT / MODEL / REACTION DIAGRAM ...:

10. OBSERVATION TABLE / LOOKUP TABLE / TRUTH TABLE ...:

11. FORMULA / CALCULATIONS ...:

12. GRAPHS / OUTPUTS ...:

13. RESULTS & ANALYSIS ...:

14. OUTCOME & CONCLUSIONS ...:

Page No.: 43/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


15. REMARKS

FACULTY SIGNATURE

1. EXPERIMENT NO: Date Planned Date Conducted Marks


XVIII 11/03/13
14/03/13

2. TITLE:
Write a java program that works as a simple calculator.Use a grid layout to arrange buttons for
the digits +,-,*,/,% operations.Adda text field to display the result

3. LEARNING OBJECTIVES:
students can write the java program on grids.

4. AIM:
Write a java program that works as a simple calculator.Use a grid layout to arrange buttons for
the digits +,-,*,/,% operations.Adda text field to display the result

5. MATERIAL / EQUIPMENT REQUIRE ...:


 A good configured PC
 JDK software

6. THEORY / HYPOTHESIS ...:

Page No.: 44/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
The GridLayout class is a layout manager that lays out a container's components in a rectangular
grid. The container is divided into equal-sized rectangles, and one component is placed in each
rectangle. For example, the following is an applet that lays out six buttons into three rows and
two columns:

7. BACKGROUND INFORMATION ...:

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


students should know the concept of grid layout.

8. PROCEDURE / PROGRAMME / ACTIVITY ...:


import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class Calculator extends Applet implements ActionListener
{
TextField t1;
String a="",b;
String oper="",s="",p="";
int first=0,second=0,result=0;
Panel p1;
Button b0,b1,b2,b3,b4,b5,b6,b7,b8,b9;
Button add,sub,mul,div,mod,res,space;
public void init()
{
Panel p2,p3;
p1=new Panel();
p2=new Panel();
p3=new Panel();
t1=new TextField(a,20);
p1.setLayout(new BorderLayout());
p2.add(t1);
b0=new Button("0");
b1=new Button("1");
b2=new Button("2");
b3=new Button("3");
b4=new Button("4");
b5=new Button("5");
b6=new Button("6");
b7=new Button("7");
b8=new Button("8");
b9=new Button("9");
add=new Button("+");
sub=new Button("-");
mul=new Button("*");
div=new Button("/");
mod=new Button("%");
res=new Button("=");
space=new Button("c");
p3.setLayout(new GridLayout(4,4));
b0.addActionListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
add.addActionListener(this);
sub.addActionListener(this);

Page No.: 45/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
mul.addActionListener(this);
div.addActionListener(this);
mod.addActionListener(this);
res.addActionListener(this);
space.addActionListener(this);
p3.add(b0);
p3.add(b1);

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


p3.add(b2);
p3.add(b3);
p3.add(b4);
p3.add(b5);
p3.add(b6);
p3.add(b7);
p3.add(b8);
p3.add(b9);
p3.add(add);
p3.add(sub);
p3.add(mul);
p3.add(div);
p3.add(mod);
p3.add(res);
p3.add(space);
p1.add(p2,BorderLayout.NORTH);
p1.add(p3,BorderLayout.CENTER);
add(p1);
}
public void actionPerformed(ActionEvent ae)
{
a=ae.getActionCommand();
if(a=="0"||a=="1"||a=="2"||a=="3"||a=="4"||a=="5"||a=="6"||a=="7"||a=="8"||
a=="9")
{
t1.setText(t1.getText()+a);
}
if(a=="+"||a=="-"||a=="*"||a=="/"||a=="%")
{
first=Integer.parseInt(t1.getText());
oper=a;
t1.setText("");
}
if(a=="=")
{
if(oper=="+")
result=first+Integer.parseInt(t1.getText());
if(oper=="-")
result=first-Integer.parseInt(t1.getText());
if(oper=="*")
result=first*Integer.parseInt(t1.getText());
if(oper=="/")
result=first/Integer.parseInt(t1.getText());
if(oper=="%")
result=first%Integer.parseInt(t1.getText());
t1.setText(result+"");
}
if(a=="c")
t1.setText("");
}
}
/*<applet code=Calculator width=200 height=200></applet>*/

9. BLOCK / CIRCUIT / MODEL / REACTION DIAGRAM ...:

Page No.: 46/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy

10. OBSERVATION TABLE / LOOKUP TABLE / TRUTH TABLE ...:

11. FORMULA / CALCULATIONS ...:

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


12. GRAPHS / OUTPUTS ...:

13. RESULTS & ANALYSIS ...:

14. OUTCOME & CONCLUSIONS ...:

15. REMARKS

FACULTY SIGNATURE
1. EXPERIMENT NO: Date Planned Date Conducted Marks
IIX 18/03/13
21/03/13

2. TITLE:
Program for handling mouse events

3. LEARNING OBJECTIVES:
students can write the program on mouse events.

4. AIM:
Write a java program for handling mouse events

5. MATERIAL / EQUIPMENT REQUIRE ...:


 A good configured PC
 JDK software

6. THEORY / HYPOTHESIS ...:


An event which indicates that a mouse action occurred in a component. A mouse action is
considered to occur in a particular component if and only if the mouse cursor is over the
unobscured part of the component's bounds when the action happens. Component bounds can be
obscurred by the visible component's children or by a menu or by a top-level window. This event
is used both for mouse events (click, enter, exit) and mouse motion events (moves and drags)

7. BACKGROUND INFORMATION ...:


students should know what is the event

Page No.: 47/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
8. PROCEDURE / PROGRAMME / ACTIVITY ...:
import java.io.*;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
/*<applet code=Mouse height=400 width=400></applet>*/
public class Mouse extends Applet implements MouseListener,MouseMotionListener

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


{
String txt="";
int x=10,y=30;
public void init()
{
addMouseListener(this);
addMouseMotionListener(this);
}
public void mouseClicked(MouseEvent me)
{
txt="Mouse Clicked";
setForeground(Color.pink);
repaint();
}
public void mouseEntered(MouseEvent me)
{
txt="Mouse Entered";
repaint();
}
public void mouseExited(MouseEvent me)
{
txt="Mouse Exited";
setForeground(Color.blue);
repaint();
}
public void mousePressed(MouseEvent me)
{
txt="Mouse Pressed";
setForeground(Color.blue);
repaint();
}
public void mouseMoved(MouseEvent me)
{
txt="Mouse Moved";
setForeground(Color.red);
repaint();
}
public void mouseDragged(MouseEvent me)
{
txt="Mouse Dragged";
setForeground(Color.green);
repaint();
}
public void mouseReleased(MouseEvent me)
{
txt="Mouse Released";
setForeground(Color.yellow);
repaint();
}
public void paint(Graphics g)
{
g.drawString(txt,30,40);
showStatus("Mouse events Handling");
}
}

Page No.: 48/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy

9. BLOCK / CIRCUIT / MODEL / REACTION DIAGRAM ...:

10. OBSERVATION TABLE / LOOKUP TABLE / TRUTH TABLE ...:

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


11. FORMULA / CALCULATIONS ...:

12. GRAPHS / OUTPUTS ...:

13. RESULTS & ANALYSIS ...:

14. OUTCOME & CONCLUSIONS ...:

15. REMARKS

FACULTY SIGNATURE

Page No.: 49/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


1. EXPERIMENT NO: Date Planned Date Conducted Marks
XX 25/03/13
28/03/13

2. TITLE:
Write a java program that creates three threads.First thread displays”Good Morning”
every one second,the second thread displays “Hello” every two seconds and the third thread
displays “Welcome” every three seconds

3. LEARNING OBJECTIVES:
students will write the program on threads.

4. AIM:
Write a java program that creates three threads.First thread displays”Good Morning”
every one second,the second thread displays “Hello” every two seconds and the third thread
displays “Welcome” every three seconds

5. MATERIAL / EQUIPMENT REQUIRE ...:


 A good configured PC
 JDK software

6. THEORY / HYPOTHESIS ...:


A thread is a thread of execution in a program. The Java Virtual Machine allows an application to
have multiple threads of execution running concurrently.

7. BACKGROUND INFORMATION ...:


students should know what is thread.

8. PROCEDURE / PROGRAMME / ACTIVITY ...:


class Frst implements Runnable
{
Thread t;
Frst()
Page No.: 50/55
Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
{
t=new Thread(this);
System.out.println("Good Morning");
t.start();
}
public void run()
{

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


for(int i=0;i<10;i++)
{
System.out.println("Good Morning"+i);
try{
t.sleep(1000);
}
catch(Exception e)
{
Syste
}
}
}
class sec implements Runnable
{
Thread t;
sec()
{
t=new Thread(this);
System.out.println("hello");
t.start();
}
public void run()
{
for(int i=0;i<10;i++)
{
System.out.println("hello"+i);
try{
t.sleep(2000);
}
catch(Exception e)
{
System.out.println(e);
}
}
}
}
class third implements Runnable
{
Thread t;
third()
{
t=new Thread(this);
System.out.println("welcome");
t.start();
}
public void run()
{
for(int i=0;i<10;i++)
{
System.out.println("welcome"+i);
try{
t.sleep(3000);
}
catch(Exception e)
{
System.out.println(e);
Page No.: 51/55
Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
}
}
}
}
public class Multithread
{
public static void main(String arg[])

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


{
new Frst();
new sec();
new third();
}
}

9. BLOCK / CIRCUIT / MODEL / REACTION DIAGRAM ...:

10. OBSERVATION TABLE / LOOKUP TABLE / TRUTH TABLE ...:

11. FORMULA / CALCULATIONS ...:

12. GRAPHS / OUTPUTS ...:

13. RESULTS & ANALYSIS ...:


good morning
hello
good morning0
hello0
welcome0

14. OUTCOME & CONCLUSIONS ...:

Page No.: 52/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy

15. REMARKS

FACULTY SIGNATURE

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


1. EXPERIMENT NO: Date Planned Date Conducted Marks
XXI 04/04/13
08/04/13

2. TITLE:
Write a java program that correctly implements producer consumer problem using the concept
of inter thread communication

3. LEARNING OBJECTIVES:
students can write the program on thread

4. AIM:
Write a java program that correctly implements producer consumer problem using the concept
of inter thread communication

5. MATERIAL / EQUIPMENT REQUIRE ...:


 A good configured PC
 JDK software

6. THEORY / HYPOTHESIS ...:


A thread is a thread of execution in a program. The Java Virtual Machine allows an application to
have multiple threads of execution running concurrently

7. BACKGROUND INFORMATION ...:


students should know what is thread

8. PROCEDURE / PROGRAMME / ACTIVITY ...:


import java.lang.*;
import java.lang.Thread;
class Q
{
int n;
boolean valueSet=false;
synchronized int get()
{
if(!valueSet)
try{
wait();
}
catch(InterruptedException e)
{
System.out.println("InterruptedException catch");

Page No.: 53/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
}
System.out.println("got:"+n);
valueSet=false;
notify();
return n;
}
synchronized void put(int n)

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


{
if(valueSet)
try{
wait();
}
catch(InterruptedException e)
{
System.out.println("InterruptedException catch");
}
this.n=n;
valueSet=true;
System.out.println("put:"+n);
notify();
}
}
class Producer implements Runnable
{
Q q;
Producer(Q q)
{
this.q=q;
new Thread(this,"producer").start();
}
public void run()
{
int i=0;
while(true)
{
q.put(i++);
}
}
}
class Consumer implements Runnable
{
Q q;
Consumer(Q q)
{
this.q=q;
new Thread(this,"consumer").start();
}
public void run()
{
while(true)
{
q.get();
}
}
}
class PCFixed
{
public static void main(String args[])
{
Q q=new Q();
new Producer(q);
new Consumer(q);
}
Page No.: 54/55
Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org
Jaya Prakash Narayan Educational Society Group of Institutions
Faculty of Engineering / Faculty of Pharmacy
}

9. BLOCK / CIRCUIT / MODEL / REACTION DIAGRAM ...:

10. OBSERVATION TABLE / LOOKUP TABLE / TRUTH TABLE ...:

JPNES – FOE – Btech- OBJECT ORIENTED PROGRAMMING LAB – A SWAPNA


11. FORMULA / CALCULATIONS ...:

12. GRAPHS / OUTPUTS ...:

13. RESULTS & ANALYSIS ...:

14. OUTCOME & CONCLUSIONS ...:

15. REMARKS

FACULTY SIGNATURE

Page No.: 55/55


Opposite Bhaghiratha Colony, JPN Nagar, Boothpur Road, MAHABUBNAGAR– 509001, AP (INDIA)
Phone: 91-8542-276111 / 33 / 44 / 55 Fax: 276122, Web: www.jpnes.org Email: director@jpnes.org

You might also like