Vous êtes sur la page 1sur 15

MCS-021

Question.1
Modify the bubble sort algorithm in which the direction of bubbling changes in each iteration: in one iteration, the
smallest element is bubbled up; in the next, the largest is bubbled down; in the net, the second smallest is bubbled up;
and so forth. Write an algorithm in C to implement this and find its time complexity.
Ans.
Bubble sort with Required Modification:

void bubble(int x[],int n)


{
int hold,j,pass;
int switched=TRUE;
for(pass=0;pass<n-1&&switched==TRUE; pass++)
{ /*outer loop controls the number of pass */
switched=FLASE;
for(j=0; j<n-pass-1; j++)
/*inner loop governs each individual pass*/
if(pass/2)
if(x[j]>x[j+1])
{
/*elements out of order */
/*an interchange is necessary */
switched=TRUE;
hold=x[j];
x[j]=x[j+1]
x[j+1]=hold;
}/*end if */
else
if(x[j]<x[j+1])
{
switched=TRUE;
hold=x[j];
x[j]=x[j+1];
x[j+1]=hold;
}/* end if */
}/*end for*/
/* end bubble */

Question 2:
Write an algorithm in C to convert an infix expression to a postfix expression. Execute your algorithm with the
following infix expression as your input.
(m+n)*(k+p)/(g/h)  (a  b/c)
Note: you must execute the program and submit the program logic, sample inputs and outputs along with the necessary
documentation for this question. Assumptions can be made wherever necessary.
Ans
Algorithm converts an expression from infix to postfix:
Let us now present an outline of an algorithm to an infix without parentheses into a postfix string. Since we assume no
parentheses in the input string, the only governor of the order in which operators appear in the postfix is precedence. (The line
numbers that appear in the algorithm will be used for future reference.)
opstk=the empty stack;
while=(not end of input) {
symb=next input character;
if(symb is an operand)
add symd to the postfix string
else {
while (!empty (opstk)&& pred (stack top (opstk),symb)) {
topsymo=pop (opstk);
add topsymb to the postfix string;
}/* end while */
push (opstk,symb);
}/* end else */
}/* end while */
/* output any remaining operators */
while (! Empty (opstk);
top symb=pop(opstk);
add topsymb to the postfix string;
MCS-025 1 http://geocities.com/ignoumca/
}/* end while */
Simulate the algorithm with such infix strings as “A*B+C*D” and “A+B*C$D$E” to convince yourself that it is correct. What
modification must be made to this algorithm to accommodate parentheses? The answer is surprisingly little. When a opening
parenthesis is read, it must push into the stack. This can be done by establishing the convention that prod(op,‘(‘) equals
FLASE, for any operator symbol op other than a ring parenthesis. In addition, we define prod(‘(‘,op) to be FLASE for any
operator symbol op. this ensures that an operator symbol appearing after a left parenthesis is pushed onto the stack.
However, since the closing parenthesis should not be pushed onto stack, line g is replaced by the statement.

if(empty)||symd!=‘)’)
push(opstk,symb);
else /* pop the open parenthesis and discard it */
topsymb=pop(opstk);

we illustrate this algorithm on following example


(m+n)*(k+p)/(g/h) (ab/c)

Input Output
S.No. Symbol Postfix string Opstk
1 ( ……. (
2 m m (
3 + m (+
4 n mn (+
5 ) mn+ ……
6 * mn+ *
7 ( mn+ *(
8 k mn+k *(
9 + mn+k *(+
10 p mn+kp *(+
11 ) mn+kp+ *
12 / mn+kp+ */
13 ( mn+kp+ */(
14 g mn+kp+g */(
15 / mn+kp+g */(/
16 h mn+kp+gh */(/
17 ) mn+kp+gh/ */
18  mn+kp+gh/ */
19 ( mn+kp+gh/ */
20 a m n + k p + g h /a */(
21  m n + k p + g h /a */(
22 b m n + k p + g h /a b */(
23 / m n + k p + g h /a b */(
24 c m n + k p + g h /a b c
*/(/
25 ) m n + k p + g h /a b c /  / *
*/(/

Postfix Notation mn+kp+gh/abc/ /*

Program Name : In2PostFix.c

Answer :::

/*
ALGORITHM
Design a structure called INFIX.
- contains two character arrays Target and Stack that store the Postfix
expression (string) and the Operators (that would be pushed onto stack)
respectively.
- The two character pointers s and t are used in the conversion process.
- The variable Top points to the top of the Stack.
Accept arithmetic expression (consisting of digits, alphabets and operators)
from the user into a string Expr.
Assign the base address of the input string (Expr) to character pointer s.

Steps for Converting Infix to Postfix Ecpression


- If the character is space or tab, then the character skipped.
MCS-025 2 http://geocities.com/ignoumca/
- if the character is a digit or an alphabet, it is added to the TARGET
string pointed by t.
- if the character is a closing parentheses then it is added to the STACK
by push() function.
- if the character is a Operator, then
1. the topmost element from the STACK is retrieved (by pop() function).
2. Through a while loop, the priorities of the character scanned and
the character popped are compared.
*/

#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>

#define MAX 50

/* Structure for Expression */


struct infix
{
char target[MAX]; // postfix expression
char stack[MAX]; // stack for operators
char *s, *t; // for storing intermediate results
int top; // top of the stack position
};

void initinfix(struct infix *); // Initializes structure elements


void setexpr(struct infix *, char *);
void push(struct infix *, char);
char pop(struct infix *);
void convert(struct infix *);
int priority(char);
void show(struct infix);

int main( )
{
struct infix p; // infix expression
char expr[MAX]; // input expression
initinfix(&p);
clrscr();
printf("\nEnter an expression in Infix form: ");
gets(expr);
//strcpy(expr, "(m+n)*(k+p)/(g/h)$(a$b/c)");
setexpr(&p, expr);
convert(&p);
printf("\nThe Postfix expression is: ");
show(p);
getch();
return(0);
} // end of main()

/* initializes structure elements */


void initinfix(struct infix *p)
{
p->top = -1;
strcpy(p->target, "");
strcpy(p->stack, "");
p->t = p->target;
p->s = "";
} // end of initinfix

/* sets s to point to given expression */


void setexpr(struct infix *p, char *str)
{
p->s = str;
MCS-025 3 http://geocities.com/ignoumca/
} // end of setexpr

/* adds an operator to the stack */


void push(struct infix *p, char c)
{
if(p->top == MAX)
printf("\nStack is full.\n");
else
{
p->top++;
p->stack[p->top] = c;
} // Stack NOT FULL
} // end of push()

/* pops an operator from the stack */


char pop(struct infix *p)
{
char item;
if(p->top == -1)
{
printf("\nStack is empty.\n");
return(-1);
} // Stack Empty
else
{
item = p->stack[p ->top];
p->top--;
return(item);
} // Stack NOT EMPTY
} // end of pop

/* converts the given expr. from infix to postfix form */


void convert(struct infix *p)
{
char opr;
while(*(p->s))
{
/* Space OR Tab character */
if( *(p->s) == ' ' || *(p->s) == '\t')
{
p->s++;
continue;
} // end of if(space OR tab)

/* Digit OR Alphabetic character */


if(isdigit(*(p->s) ) || isalpha (*(p->s)) )
{
while(isdigit(*(p->s)) || isalpha(*(p->s)))
{
*(p->t) = *(p->s);
p->s++;
p->t++;
} // end of while(Digit OR alpha)
} // end of if(digit OR alpha)

/* Left Bracket */
if(*(p->s) == '(')
{
push(p, *(p->s));
p->s++;
} // end of if(left bracket)

/* Operators Multiplication, Addition, Division, Modular, Subtraction, Exponentiation */


if( *(p->s) == '*' || *(p->s) == '+' || *(p->s) == '/' ||
*(p->s) == '%' || *(p->s) == '-' || *(p->s) == '$' )
{
MCS-025 4 http://geocities.com/ignoumca/
if(p->top != -1 )
{
opr = pop(p);
while(priority(opr) >= priority (*(p->s)))
{
*(p->t) = opr;
p->t++;
opr = pop(p);
} // end of while(priority comparision)
push(p, opr);
push(p, *(p->s));
} // end of if(STACK NOT EMPTY)
else
push(p, *(p->s));
p->s++;
} // end of if(operators)

/* Right Bracket */
if(*(p->s) == ')')
{
opr = pop(p);
while((opr) != '(')
{
*(p->t) = opr;
p->t++;
opr = pop(p);
} // end of while(NOT Left bracket)
p->s++;
} // end of if(right bracket)
} // end of while(*(p->s))

/* Empty Stack */
while(p->top != -1)
{
opr = pop(p);
*(p->t) = opr;
p->t++;
}
*(p->t) = '\0';
} // end of convert()

/* returns the priority of an operator */


int priority(char c)
{
if(c == '$')
return(3);
if (c == '*' || c == '/' || c == '%')
return(2);
else
{
if (c == '+' || c == '-')
return(1);
else
return(0);
}
} // end of priority(operator)

/* displays the postfix form of given expr. */


void show(struct infix p)
{
printf(" %s", p.target);
} // end of show(expression)

MCS-022
Question 1:

MCS-025 5 http://geocities.com/ignoumca/
Write a shell script that prints list of every unique word (exceeding 4 characters in length) in a file in reverse
alphabetical order.

Question 2:
I. What is the output of ls-lm and ls-ml? Which option takes procedure? What is the result of is-d?
II. How would you set the IP address of a LAN card in Linux?
Question 3:
I. Protect Data by using Encrypting File system (EFS) and Recover Encrypted Data with a Data Recovery Agent.
Show the result with the help of your own example?
II. Configure Window 2000 to have a remote access feature and the result.

MCS-023

Question 1:
There are many private college affiliate to a state University. The University wants to computerize all its affiliated
colleges to keep update information about student, faculty, generate different types of reports and monitor
performance of these colleges. After creating the database you must perform the following tasks:
Produce a report showing number of student registered in each program of each college.
1. Find out number of faculty positions vacant in computer science programme in all colleges.
2. List the name of students with their enrollment nm\umber who have topped in their respective program in
their colleges.
3. Produce a report of faculties who are going to retire within 6 months.
4. List the name of the faculties with the highest number of research papers in international journals.
Ans

Relation 1 : College(college_name,college_code,location,contact_no)
Description : All those college,with are affiliated to the university are details with this Relation.
Key : College_code

Table :
College
College_name College_code Location Contact_no
Vidyanagar C0001 Anand 24556667
Nirma C0002 Ahmedabad 35664555
H.L C0003 Ahmedabad 24553452
NICM C0004 Gandhinagar 25234673
Somlalit C0005 Ahmedabad 24556345

Relation 2 : Program_pffered(college_code,program_code)
Description : This relation list programs offered by each college.
Key : College_code,program_code

Table :

Program_offered
College_code Program_code
C0001 P0001
C0002 P0002
C0003 P0003
C0004 P0001
C0004 P0002
C0005 P0004
C0005 P0005

Relation 3 : Program_detail(program_code,program_name,duration,total_credits)
Description : Details of each program can be viewed from this relation.
Key : program_code(program_code is unique for all university i.e. B.Tech(cs) ‘Computer Science’ for all college,
which offer computer Engineering.

Table:
Program_details
Program_code Program_name Duration Total_credit
P0001 MCA 3 10
MCS-025 6 http://geocities.com/ignoumca/
P0002 MBA 2 10
P0003 Computer Science 3 9
P0004 BCOM 3 12
P0005 BE 4 20

Relation 4 : Faculty_position(college_code,program_code,faculty_positions,faculty_avail)
Description : Details of each faculty positions and faculty available for each program and college is maintained in this
table.
Key : college_code,program_code.

Table:

Faculty_position
College_code Program_code Faculty_positions Faculty_avail
C0001 P0001 2 1
C0001 P0004 3 2
C0002 P0002 1 1
C0002 P0003 5 2
C0003 P0001 3 1
C0003 P0002 2 2
C0004 P0003 1 1
C0005 P0004 2 2
C0005 P0005 1 1

Relation 5 :Faculty_position(college_code,Faculty_name,Faculty_address,Faculty_contact,Faculty_qualication,
date_of_join,date_of_birth,college_code,program_code)
Description : Apersonal details of each faculty is maintained in this table. It also maintained his/her appointment details
like college,and programs are also maintained her.
Key : program_code(program_code is unique for all university i.e. B.Tech(cs) ‘Computer Science’ for all college,
which oFaculty_ID(Faculty_ID is unique for each faculty among all faculty of university)

Table:

Faculty
Faculty_ Faculty_na Faculty_addre Faculty_co Faculty Designa Date_of_joi Date_of_birt College Progr_c
ID me ss ntact _qulif tion n h _code ode
F0001 Madhvi Gurukul 24546788 MCA Leet 12/2/2004 6/1/1981 C0001 P0001
F0002 Maghna Maninagar 44564566 BSC Prof 9/4/2001 9/14/1985 C0002 P0003
F0003 Payal Gandhinagar 24546788 BCOM Leet 7/19/2005 5/11/1980 C0003 P0002
F0004 Devendra Kalapinagar 56734556 MBA Leet 1/8/2002 1/12/1978 C0004 P0004
F0005 Jainam Naranpure 24546234 BE Leet 4/22/2006 3/11/1984 C0001 P0001

Relation 6 : Faculty_Paper(Faculty_ID,research_topic,paper_title,journal,publish_at)
Description : Details of each resurch paper published by each faculty is record in this table.
Key : Faculty_ID,paper_title.

Table:

Faculty_paper
Faculty_ID Research_topic Paper_title Journal Publish_at
F0001 Web Service .NET paper .NET International
F0002 WareHousing WareHousing MBA National
F0003 System Lifecycle SAD MCA International
F0004 Accounting Princples Accounting BCOM International
F0005 Bio-Checmist Bio-Checmist BSC National

Relation 7 : Student(Student_Code,Fname,MName,LName,correspondence_address,Present_address, local_contact,


permanent_contact,result,program_code,college_code)
Description : A Student can get enrollment to single program from one college only. Student’s enrollment details,
program details, and personal details are maintained in this relation. It also stores grade of student for the
programme.
Key : Student_code,program_code,college_code.

Table :

MCS-025 7 http://geocities.com/ignoumca/
Student
Studen name MNa Lname correspond Present_ad Local_co Permane Res Progra College
t_code me ence_addre dress ntact nt_contac ult m_code _code
ss t
S0001 Meena U Gazzar Ahmedabad Ahmedabad 3434234 23423444 67 P0001 C0001
S0002 Jinal L Patel Ahmedabad Ahmedabad 4563424 4563424 80 P0002 C0002
S0003 Pinky O Sanghavi Gandhinagar Gandhinagar 6734444 6734444 75 P0003 C0004
S0004 Jaya A Mehta Gandhinagar Gandhinagar 56453245 56453245 69 P0004 C0003
S0005 Sagar P Nayak Anand Ahmedabad 4532434 12323234 76 P0005 C0005
S0006 Jainam U Shah Ahmedabad Ahmedabad 2455344 2455344 59 P0002 C0003

Write following SQL to generate reports

Report 1:
SQL
SELECT Sum(Faculty_position.faculty_positions-Faculty_position.faculty_avail) AS Vacancy, Faculty_position.college_code
FROM Faculty_position INNER JOIN Program_details ON Faculty_position.program_code=Program_details.program_code
Where(((Program_detail.program_name)=’Computer Science’)) Group BY Faculty_position.college_code;

OUTPUT:

Vacancy College_code
3 C0002
0 C0004

Report 2:
SQL :
SELECT Student.Stydent_code, Student.Fname,Student.MName,Student.Lname,Max(Student.result) AS MaxOfresult,
Student.college_code,Program_detail.program_name, College.college_name FROM(College INNER JOIN Student ON
College.college_code=Stuydent.college_code) INNER JOIN Program_detail ON
Student.program_code=program_detail.program_code, Student.Fname,Student.college_code,
Program_detail.program_name,College.college_name;

OUTPUT:

Student Fname MName Lname MaxOf result College code Program name College_name
code
S0001 Meena U Gazzar 67 C0001 MCA Vidyanagar
S0002 Jinal L Patel 80 C0002 MBA Nirma
S0003 Pinky O Sanghavi 75 C0004 Computer NICM
Science
S0004 Jaya A Mehta 69 C0003 BCOM H.L
S0005 Sagar P Nayak 76 C0005 BE Somlalit
S0006 Jainam U Shah 59 C0003 MBA H.L

Report 3:
SQL:
SELECT faculty_id,Faculty_name FROM faculty HHERE DATEDIFF(‘m’,CURDATE,’12/2/2007’)<=6;

OUTPUT:
Faculty_ID
F0005

Report 4:
SQL
SELECT faculty.faculty_name from Where faculty.faculty_id In (select faculty.faculty_id from
Faculty.publish_at=’International’ Group by Faculty.faculty_id having Count(faculty.paprer_title)>=(select count(paper_title)
From faculty_paper Where publish_at=’International;’ Group by faculty_id));

OUTPUT:
Faculty_name
Madhavi

MCS-025 8 http://geocities.com/ignoumca/
Meghna

MCS-024
Question 1:
I. Write a java program to demonstrate the use of different bitwise operators.
II. Write a java program, which create variable size array in java. This program also should take two 33
matrices as input and display sum of these matrices.

Question 2:
I. Write a java program that take your name as input and display the reverse of it. Also read names of two of
your friends and attend it to your name and display the final string.
II. Write a java program to explain how a thread with higher priority will execute before a thread of low priority.

Question 3:
I. Write a java program to create a file and copy the contents of an already existing file into it.
II. Create an Applet program, which takes your name, address, and a detailed description of advantages of using
java-programming language. After giving input when you press submit button your program display “You are
right, java is really a very good programming language”, Use appropriate GUI components and layout in this
program.

Question 1:
(i) Write a Java program to demonstrate the use of different bitwise operators.

Answer::
Bitwise operators: Java provides Bit wise operators to manipulate the contents of variables at the bit level. These variables
must be of numeric data type (char, short, int, or long). Java provides seven bitwise operators. They are AND, OR, Exclusive-
OR, Complement, Left-shift, Signed Right-shift, and Unsigned Right-shift. An example program is shown below that
demonstrates the different Bit wise operators in java.
The result of applying bitwise operators between two corresponding bits in the operands is shown in the Table below.

A B ~A A&B A|B A^B

1 1 0 1 1 0

1 0 0 0 1 1

0 1 1 0 1 1

0 0 1 0 0 0

Program:
public class BitwiseOperatorsDemo {
public static void main(String args[]){
int x = 0xFAEF; //1 1 1 1 1 0 1 0 1 1 1 0 1 1 1 1
int y = 0xF8E9; //1 1 1 1 1 0 0 0 1 1 1 0 1 0 0 1

System.out.println("This Program demonstrate the use of different Bitwise Operator in Java");

System.out.println("x & y : "+(x & y));


System.out.println("x | y : "+(x | y));
System.out.println("x ^ y : "+(x ^ y));
System.out.println("~x : "+(~x));
System.out.println("x << y : "+(x << y));
System.out.println("x >> y : "+(x >> y));
System.out.println("x >>> y : "+(x >>> y));

//There is no unsigned left shift operator


}
}
MCS-025 9 http://geocities.com/ignoumca/
/*::::OUTPUT::::::::::::
This Program demonstrate the use of different Bitwise Operator in Java
x & y : 63721
x | y : 64239
x ^ y : 518
~x : -64240
x << y : 32890368
x >> y : 125
x >>> y : 125
*/

(ii) Write a Java program, which create variable size array in Java. This program also should take two 3× 3 matrices
as input and display sum of these matrices.

Answer ::

import java.io.*;
public class MatrixMult {

/** Creates a new instance of MatrixMult */


public MatrixMult() {
}

public static void main(String[] args) {


int row1=0,col1=0,row2=0,col2=0,tempVal=0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try{
System.out.println("Enter rows and columns of first matrix::");
row1=Integer.parseInt(br.readLine());
col1=Integer.parseInt(br.readLine());

System.out.println("Enter rows and columns of second matrix::");


row2=Integer.parseInt(br.readLine());
col2=Integer.parseInt(br.readLine());

int [][] matrix1 = new int[row1][col1];


int [][] matrix2 = new int[row2][col2];

System.out.println("enter values for matrix 1:");


for(int i=0;i<row1;i++){
for(int j=0;j<col1;j++){
matrix1[i][j]=Integer.parseInt(br.readLine());
}
}

System.out.println("enter values for matrix 2:");


for(int i=0;i<row2;i++){
for(int j=0;j<col2;j++){
matrix2[i][j]=Integer.parseInt(br.readLine());
}
}

if(col1 == row2){
System.out.println("The answer is:");
for(int i=0;i<row1;i++){
for(int j=0;j<col2;j++){
tempVal=0;
for(int k=0;k<col1;k++){
tempVal+= matrix1[i][k]*matrix2[k][j];
}
System.out.print(tempVal+"\t");
}
System.out.println();
}
}else{
MCS-025 10 http://geocities.com/ignoumca/
System.out.println("Multiplication is not possible::");
}
}catch(IOException e){
e.printStackTrace();
}
}

}
/*
::::::::::::OUTPUT::::::::::::::
Enter rows and columns of first matrix::
3
3
Enter rows and columns of second matrix::
3
3
enter values for matrix 1:
1
1
1
1
1
1
1
1
1
enter values for matrix 2:
2
2
2
2
2
2
2
2
2
The answer is:
6 6 6
6 6 6
6 6 6
*/

Question 2:
(i) Write a Java program that take your name as input and display the reverse of it. Also read names of two of your
friends and attend it to your name and display the final string.

Answer ::

import java.io.*;
public class StringBufferOp {

/** Creates a new instance of StringBufferOp */


public StringBufferOp() {
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
String str2 = null;
StringBuffer str1 = new StringBuffer("Rikin Patel");
System.out.println("string buffer capacity:::"+str1.capacity());
System.out.println("Enter string to concate with str1::");
try{
str2 = br.readLine();
MCS-025 11 http://geocities.com/ignoumca/
}catch(Exception e){
e.printStackTrace();
}
str1.append(str2);
System.out.println("String after concat:::"+str1);
}

/*::::OUTPUT:::::
string buffer capacity:::27
Enter string to concate with str1::
NISHIT DHARA
String after concat:::Rikin Patel NISHIT DHARA
*/

(ii) Write a Java program to explain how a thread with higher priority will execute before a thread of low priority

Answer:::

import javax.swing.*;
import java.awt.event.*;

public class ThreadPriorityDemo extends JFrame {

private HighThread high;


private LowThread low;
private JTextArea output;

public ThreadPriorityDemo()
{
super( "Demo" );
output = new JTextArea( 10, 20 );
getContentPane().add( output );
setSize( 250, 200 );
setVisible( true );

high = new HighThread( output );


high.start();

low = new LowThread( output );


low.start();
}

public static void main( String args[] )


{
ThreadPriorityDemo app = new ThreadPriorityDemo();
app.addWindowListener(
new WindowAdapter() {
public void windowClosing( WindowEvent e )
{
System.exit( 0 );
}
}
);

}
}

class HighThread extends Thread {


private JTextArea display;

public HighThread( JTextArea a )


{
display = a;
setPriority( Thread.MAX_PRIORITY );
MCS-025 12 http://geocities.com/ignoumca/
}

public void run()


{
for ( int x = 1; x <= 5; x++ )
display.append( "High Priority Thread!!!\n" );
}
}

class LowThread extends Thread {


private JTextArea display;

public LowThread( JTextArea a )


{
display = a;
setPriority( Thread.MIN_PRIORITY );
}

public void run()


{
for ( int y = 1; y <= 5; y++ )
display.append( "Low Priority Thread!!!\n" );
}
}

/*::::::::OUTPUT:::::::*/

Question 3:
(i) Write a java program to create a file and copy the contents of an already existing file into it.

Answer::

import java.io.*;
public class FileCopy {

/** Creates a new instance of FileCopy */


public FileCopy() {
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter source and destination file::");


File source = new File(br.readLine());
File dest = new File(br.readLine());

BufferedReader reader = new BufferedReader(new FileReader(source));


PrintWriter writer = new PrintWriter(new FileWriter(dest));

MCS-025 13 http://geocities.com/ignoumca/
int str = 0;
while((str = reader.read()) > 0){
writer.print((char)str);
}
writer.flush();
writer.close();
reader.close();
System.out.println("File Copy Completed");
}catch(Exception e){
e.printStackTrace();
}

/*
::::::::OUTPUT:::::::::::::
Enter source and destination file::
C:/rikin.txt
c:/temp.txt
File Copy Completed
*/

(ii) Create an Applet program, which takes your name, address, and a detailed description of advantages of using java-
programming language. After giving input when you press submit button your program display“You are right, java is
really a very good programming language”. Use appropriate GUI components and layout in this program

Answer:::

Applet ::: An applet is a small Java application that can be sent along with a Web page to a user, much the same way an
image is included. It is a software component that runs in the context of another program, for example a web browser.

import java.applet.Applet;
import java.awt.Button;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class AppletDemo extends Applet implements ActionListener{

private TextField nametxt = new TextField();


private TextArea addresstxt = new TextArea(50,3);
private TextArea optxt = new TextArea(50,3);
private TextArea desctxt = new TextArea(50,3);

private Label namelbl = new Label("NAME:::");


private Label addresslbl = new Label("Address::::");
private Label oplbl = new Label("Output:::");
private Label desclbl = new Label("Description");

private Button submitbtn = new Button("SUBMIT");


private Button clearbtn = new Button("CLEAR");

public void start() {


this.setLayout(new GridLayout(5,2));

this.add(namelbl);
this.add(nametxt);
this.add(addresslbl);
this.add(addresstxt);
this.add(desclbl);
this.add(desctxt);
MCS-025 14 http://geocities.com/ignoumca/
this.add(oplbl);
this.add(optxt);
this.add(submitbtn);
this.add(clearbtn);

submitbtn.addActionListener(this);
clearbtn.addActionListener(this);
}

public void actionPerformed(ActionEvent ae) {


if(ae.getSource().equals(submitbtn)){
optxt.setText("You are right, java is really a very good programming language");
}else if(ae.getSource().equals(clearbtn)){
nametxt.setText("");
addresstxt.setText("");
optxt.setText("");
}

/*:::::::OUTPUT:::::::::*/

MCS-025 15 http://geocities.com/ignoumca/

Vous aimerez peut-être aussi