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

BCA Java Program

The document appears to be a student exam paper containing details of a BCA degree examination for a student. It includes fields for the student's name, registration number, subject, and semester. It also contains instructions for the internal and external examiners and leaves space for the student to provide answers and details of practical work completed for various topics during the semester, with space for signatures and date of examination.

Uploaded by

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

BCA Java Program

The document appears to be a student exam paper containing details of a BCA degree examination for a student. It includes fields for the student's name, registration number, subject, and semester. It also contains instructions for the internal and external examiners and leaves space for the student to provide answers and details of practical work completed for various topics during the semester, with space for signatures and date of examination.

Uploaded by

bagya lakshmi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

PAVENDAR BHARATHIDASAN COLLEGE OF ARTS AND SCIENCE

THANJAI NATARAJAN NAGAR,

MATHUR, PUDUKOTTAI ROAD, TIRUCHIRAPPALLI, PINCODE-622515.

DEPARTMENT OF COMPUTER APPLICATION

BCA DEGREE EXAMINATION

NAME : ________________________________

REG.NO : ________________________________

SUBJECT : ________________________________

SEMESTER : ________________________________
PAVENDAR BHARATHIDASAN COLLEGE OF ARTS AND SCIENCE

THANJAI NATARAJAN NAGAR,

MATHUR, PUDUKOTTAI ROAD, TIRUCHIRAPPALLI, PINCODE-622515.

DEPARTMENT OF COMPUTER APPLICATION

Certified that this bonafide recorded or the _______________ practical work done
by ____________________ for ___________ semester in the subject ___________________
During the academic year ______________

Register No:___________________________

STAFF INCHARGE HEAD OF THE DEPARTMENT

Submitted for the practical examination held on ___________________

INTERNAL EXAMINER EXTERNAL EXAMINER


INDEX

S.NO DATE TITLE PAGE NO SIGNATURE

1 Sort the given numbers using arrays

2 FIND and REPLACE operations

3 Calculator to perform basic arithmetic


operations

4 Area of a rectangle

5 Student’s percentage and grade

6 Draw circle or triangle or square

7 Multiple inheritance

8 Create threads and assign priorities

9 Develop an applet to play multiple audio


clip

10 Create a window with three check boxes


SORT THE GIVEN NUMBER USING ARRAYS

Sort.java

import java.io. * ;
class sort
{
public static void main ( String args []) throws IOException
{
InputStreamReader in = new InputStreamReader ( System.in ) ;
BufferedReader br =new BufferedReader ( in ) ;
int a[]= new int [ 20 ] ;
int i , j , n , temp ;
System.out.print ( " Enter value for n : " );
n = Integer.parseInt ( br.readLine ( ) ) ;
for ( i = 1 ; i <=n ; i ++ )

a[i] = Integer.parseInt ( br.readLine ());


for ( i = 1 ; i < n ; i ++ )
{
for ( j=i + 1 ; j <=n ; j++ )
{
if(a [ i ] > a [ j ] )
{
temp = a[i] ;
a [ i ] =a[j] ;
a[j] = temp ;
}
}
}
System.out.println ( " Ascending order is " ) ;
for (i =1 ; i <= n ; i ++ )
System.out.println ( a [ i ] ) ;
System.out.println ( " Descending order is " ) ;
for ( i = n ; i >=1 ; i-- )
System.out.println ( a [ i ] ) ;
}
}
OUTPUT

C:\Users\BAGYA\Desktop>javac sort.java

C:\Users\BAGYA\Desktop>java sort
Enter value for n : 5
77
89
90
5
56
Ascending order is
5
56
77
89
90
Descending order is
90
89
77
56
5
FIND AND REPLACE OPERATION

Findrep.java

import java.util.regex . *;
class findrep
{
public static void main ( String argt [] )
{
Pattern p= Pattern.compile ( " He " ) ;
Matcher m=p.matcher ( " He is a doctor . He is a good human being");
if (m.find ( ) )
{
System.out.println(m.replaceAll ( " Raja " )) ;
}
else
System.out.println ( " not found " ) ;
}
}
OUTPUT

C:\Users\BAGYA\Desktop>javac Findrep.java

C:\Users\BAGYA\Desktop>java Findrep
Raja is a doctor . Raja is a good human being
CALAULATOR TO PERFORM BASIC ARITHMETIC OPERATIONS

CalculatorApplet.java

import java.applet.Applet;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class CalculatorApplet extends Applet implements ActionListener {
int i, a, b, c;
TextField t;
char op;
Button ad, sub, mul, div, mod, eql, clr;
Button b0, b1, b2, b3, b4, b5, b6, b7, b8, b9;

public void init() {


setLayout(null);
setBackground(Color.blue);
setForeground(Color.black);
t = new TextField(10);
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");
ad = new Button("+");
sub = new Button("-");
mul = new Button("*");
div = new Button("/");
mod = new Button("%");
eql = new Button("=");
clr = new Button("CLR");
add(t);
t.setBounds(100, 70, 150, 25);
add(b0);
b0.setBounds(100, 100, 30, 25);
add(b1);
b1.setBounds(140, 100, 30, 25);
add(b2);
b2.setBounds(180, 100, 30, 25);
add(b3);
b3.setBounds(220, 100, 30, 25);
add(b4);
b4.setBounds(100, 130, 30, 25);
add(b5);
b5.setBounds(140, 130, 30, 25);
add(b6);
b6.setBounds(180, 130, 30, 25);
add(b7);
b7.setBounds(220, 130, 30, 25);
add(b8);
b8.setBounds(100, 160, 30, 25);
add(b9);
b9.setBounds(140, 160, 30, 25);
add(ad);
ad.setBounds(180, 160, 30, 25);
add(sub);
sub.setBounds(220, 160, 30, 25);
add(mul);
mul.setBounds(100, 190, 30, 25);
add(div);
div.setBounds(140, 190, 30, 25);
add(mod);
mod.setBounds(180, 190, 30, 25);
add(eql);
eql.setBounds(220, 190, 30, 25);
add(clr);
clr.setBounds(100, 220, 150, 25);
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);
ad.addActionListener(this);
sub.addActionListener(this);
mul.addActionListener(this);
div.addActionListener(this);
mod.addActionListener(this);
eql.addActionListener(this);
clr.addActionListener(this);
}
public void paint(Graphics g) {
g.drawRect(70, 50, 200, 210);
}

@Override
public void actionPerformed(ActionEvent ae) {
try {
if (ae.getSource() == b0) {
t.setText(t.getText() + "0");
}
if (ae.getSource() == b1) {
t.setText(t.getText() + "1");
}
if (ae.getSource() == b2) {
t.setText(t.getText() + "2");
}
if (ae.getSource() == b3) {
t.setText(t.getText() + "3");
}
if (ae.getSource() == b4) {
t.setText(t.getText() + "4");
}
if (ae.getSource() == b5) {
t.setText(t.getText() + "5");
}
if (ae.getSource() == b6) {
t.setText(t.getText() + "6");
}
if (ae.getSource() == b7) {
t.setText(t.getText() + "7");
}
if (ae.getSource() == b8) {
t.setText(t.getText() + "8");
}
if (ae.getSource() == b9) {
t.setText(t.getText() + "9");
}
if (ae.getSource() == ad) {
a = Integer.parseInt(t.getText());
t.setText("");
op = '+';
}
if (ae.getSource() == sub) {
a = Integer.parseInt(t.getText());
t.setText("");
op = '-';
}
if (ae.getSource() == mul) {
a = Integer.parseInt(t.getText());
t.setText("");
op = '*';
}
if (ae.getSource() == div) {
a = Integer.parseInt(t.getText());
t.setText("");
op = '/';
}
if (ae.getSource() == mod) {
a = Integer.parseInt(t.getText());
t.setText("");
op = '%';
}
if (ae.getSource() == eql) {
b = Integer.parseInt(t.getText());
if (op == '+') {
c = a + b;
}
if (op == '-') {
c = a - b;
}
if (op == '*') {
c = a * b;
}
if (op == '/') {
c = a / b;
}
if (op == '%') {
c = a % b;
}
t.setText(String.valueOf(c));
}
if (ae.getSource() == clr) {
t.setText("");
}
} catch (Exception ex) {
t.setText("");
}
}
}
CalculatorApplet.html

<html>
<head>
</head>
<body>
<applet code = "CalculatorApplet.class" width = "350" height = "300"></applet>
</body>
</html>
OUTPUT

C:\Users\BAGYA\Desktop>javac CalculatorApplet.java

C:\Users\BAGYA\Desktop>appletviewer CalculatorApplet.html
AREA OF A RECTANGLE

Rect1.java

import java.io . *;
class rect
{
double l,b,area ;
rect ( double len , double bre )
{
l = len ;
b = bre ;
}
void cal ( )
{
area = l * b ;
System.out.println ( " Area of Rectangle is : " + area ) ;
}
}
class rect1
{
public static void main ( String args [ ] ) throws IOException
{
InputStreamReader in = new InputStreamReader (System.in) ;
BufferedReader br= new BufferedReader(in) ;
double len , bre ;
System.out.print ( " Enter value for length : " ) ;
len = Double.parseDouble ( br.readLine ( )) ;
System.out.print ( " Enter value for breath :" ) ;
bre= Double.parseDouble ( br.readLine ( ) ) ;
rect r = new rect ( len , bre ) ;
r.cal ( ) ;
}
}
OUTPUT

C:\Users\BAGYA\Desktop>javac Rect1.java

C:\Users\BAGYA\Desktop>java Rect1
Enter value for length : 4
Enter value for breath :5
Area of Rectangle is : 20.0
STUDENT’S PERCENTAGE AND GRADE

Stud.java

import java.lang.*;
import java.io . *;
import java.util.*;
class sort
{
public static void main ( String args[])
{
String name , grade ;
int rno,tam,eng,maj,tot,avg ;
name = args[0] ;
rno = Integer.parseInt (args[1]);
tam= Integer.parseInt (args[2]) ;
eng = Integer.parseInt (args[3]) ;
maj =Integer.parseInt (args[4]) ;
tot =tam + eng + maj ;
avg =tot / 3 ;
System.out.println ( " Student Details " ) ;
System.out.println ( " Name : " + name ) ;
System.out.println ( " Roll No : " + rno ) ;
System.out.println ( " Tamil : " + tam ) ;
System.out.println ( " English : " + eng ) ;
System.out.println ( " Major : " + maj);
System.out.println ( " Total : " + tot ) ;
System.out.println ( " Average : " + avg ) ;
System.out.println ( " Grade :");
if ( avg >=80 )
System.out.println ( " Distinction " ) ;
else if ( avg >= 60 )
System.out.println ( " 1st grade " ) ;
else if ( avg >= 50 )
System.out.println ( " 2nd grade " ) ;
else if ( avg >= 40 )
System.out.println ( " 3rd grade " ) ;
else
System.out.println ( " 4rd grade " ) ;
}
}
OUTPUT

C:\Users\BAGYA\Desktop>java sort bagya 1815 90 60 50


Student Details
Name : bagya
Roll No : 1815
Tamil : 90
English : 60
Major : 50
Total : 200
Average : 66
Grade :
1st grade
DRAW CIRCLE OR TRIANGLE OR SQUARE

App.java

import java.applet . * ;
import java.awt.* ;
//<applet code=App.class" width="500" height="500">< / applet >
public class App extends Applet
{
public void paint ( Graphics g )
{
int[] x={200 , 300 , 250 , 200 };
int[] y={300 , 300 , 200 , 300 } ;
g.setColor ( Color.red ) ;
g.drawOval ( 200 , 50 , 100 , 100 ) ;
g.drawRect ( 200 , 350 , 100 , 100 ) ;
g.drawPolygon ( x , y , 4 ) ;
}
}

App.html

<html>
<head>
</head>
<body>
<applet code = "App.class" width = "480" height = "500"></applet>
</body>
</html>
OUTPUT

C:\Users\BAGYA\Desktop>javac App.java

C:\Users\BAGYA\Desktop>appletviewer App.html
MUTIPLE INHERITANCE
Demo.java

interface NameId {
void get(String name, int id);
}
interface Dept {
String dept = "Computer", design = "Manager";
}
interface Salary extends NameId, Dept {
void pay(double db1);
}
class Employee implements Salary {
String name;
int id;
double bp, hra, da, ta, lic, np;
@Override
public void get(String name, int id) {
this.name = name;
this.id = id;
}
@Override
public void pay(double db1) {
this.bp = db1;
hra = bp * 0.03;
da = bp * 0.05;
ta = bp * 0.02;
lic = bp * 0.03;
np = bp + hra + da + ta - lic;
}
void display() {
System.out.println(" Department : " + dept);
System.out.println(" Designation : " + design);
System.out.println(" Name : " + name);
System.out.println(" ID : " + id);
System.out.println(" Basic Pay : " + bp);
System.out.println("net pay:" + np);
}
}
public class Demo{
public static void main(String[] args) {
Employee employee = new Employee();
employee.get("roja", 1001);
employee.pay(50000);
employee.display();
}}
OUTPUT

C:\Users\BAGYA\Desktop>javac Demo.java

C:\Users\BAGYA\Desktop>java Demo
Department : Computer
Designation : Manager
Name : mani
ID : 1001
Basic Pay : 50000.0
net pay:53500.0
CREATE THREADS AND ASSIGN PRIORITIES
Sampthread.java

import java.io.*;
import java.lang.*;
class A extends Thread
{
public void run()
{
System.out.println("Thread A started");
for(int i=1;i<=5;i++)
System.out.println("A:"+i);
System.out.println("Exited from A");
}
}
class B extends Thread
{
public void run()
{
System.out.println("Thread B started");
for(int j=1;j<=5;j++)
System.out.println("B:"+j);
System.out.println("Exited from B");
}
}
class C extends Thread
{
public void run()
{
System.out.println("Thread c started");
for(int k=1;k<=5;k++)
System.out.println("Exited from c");
}
}
class sort
{
public static void main(String args[])
{
A ob1=new A();
B ob2=new B();
C ob3=new C();
ob3.setPriority(Thread.MAX_PRIORITY);
ob2.setPriority(ob1.getPriority()+1);
ob1.setPriority(Thread.MIN_PRIORITY);
System.out.println("A is going to start");
ob1.start();
System.out.println("B is going to start");
ob2.start();
System.out.println("C is going to start");
ob3.start();
}
}
OUTPUT

C:\Users\BAGYA\Desktop>javac Sampthread.java

C:\Users\BAGYA\Desktop>java Sampthread
A is going to start
B is going to start
Thread A started
Thread B started
C is going to start
B:1
B:2
B:3
B:4
B:5
Exited from B
A:1
Thread c started
Exited from c
Exited from c
Exited from c
Exited from c
Exited from c
A:2
A:3
A:4
A:5
Exited from A
DEVELOP AN APPLET TO PLAY MULTIPLE AUDIO CLIPS
Audioex9.java

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
//<applet code="sort.class" width=300 height=300”>
//</applet>
public class sort extends Applet implements ActionListener
{
AudioClip s1,s2;
Button b1,b2;
public void init()
{
b1=new Button("Audio1");
b2=new Button("Audio2");
s1=getAudioClip(getCodeBase(),"p1.au");
s2=getAudioClip(getCodeBase(),"p2.au");
add(b1);
add(b2);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
if(s1!=null)
s1.play();
else
repaint();
}
if(e.getSource()==b2)
{
if(s2!=null)
s2.play();
else
repaint();
}
}
public void paint(Graphics g)
{
showStatus("File not found");
}
}
Audioex9.html

<html>
<head>
</head>
<body>
<applet code = "Audioex9.class" width = "480" height =

"500"></applet>
</body>
</html>
OUTPUT

C:\Users\BAGYA\Desktop>javac Audioex9.java

C:\Users\BAGYA\Desktop>appletviewer Audioex9.html
CREATE A WINDOW WITH THREE CHECK BOXES
Checkex10.java

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
//<applet code="checkex10.class" width=500 height=500>
//</applet>
public class checkex10 extends Applet implements ItemListener
{
Checkbox r,g,b;
Color c;
public void init()
{
r=new Checkbox("RED");
g=new Checkbox("GREEN");
b=new Checkbox("BLUE");
add(r);
add(g);
add(b);
r.addItemListener(this);
g.addItemListener(this);
b.addItemListener(this);
}
public void itemStateChanged(ItemEvent e)
{
if(e.getSource()==r)
{
c=Color.red;
g.setState(false);
b.setState(false);
}
if(e.getSource()==g)
{
c=Color.green;
r.setState(false);
b.setState(false);
}
if(e.getSource()==b)
{
c=Color.blue;
r.setState(false);
g.setState(false);
}
repaint();
}
public void paint(Graphics g)
{
setBackground(c);
}
}

Checkex10.html

<html>
<head>
</head>
<body>
<applet code = "checkex10.class" width = "480" height =

"500"></applet>
</body>
</html>
OUTPUT

C:\Users\BAGYA\Desktop>javac Checkex10.java

C:\Users\BAGYA\Desktop>appletviewer Checkex10.html

You might also like