Java Programming Project Overview
Java Programming Project Overview
PROJECT
PROFILE
NAME: SHIVANSH SRIVASTAVA
CLASS: 12
SECTION: G
SESSION: 2020-2021
SUBJECT: COMPUTER SCIENCE
TOPIC: PROGRAMMING IN JAVA
SCHOOL: CITY MONTESSORI
SCHOOL ALIGANJ - I
INTERNAL ASSESSMENT:
EXTERNAL ASSESSMENT:
ACKNOWLEDGEMENT
I wish to express my deep gratitude and
sincere thanks to the school Senior Principal,
Mrs. Jyoti Kashyap and Principal Mrs. Shivani
Singh for their encouragement and provided
facilities for this school project. I sincerely
appreciate their generosity by taking me into
his fold for which I shall remain indebted to
them. I extent my appreciation to Sarfaraz Sir,
our Computer teacher who guided me to the
successful completion of this project. I take
this opportunity to express my deep sense of
gratitude to his invaluable guidance, ongoing
encouragement, enormous motivation, which
has sustained my efforts at all the stages of
project development.
INDEX
SERIAL TOPIC PAGE
NO. NO.
1) Unique Digits 1-3
2) A.P. And it’s sum 4-6
3) Display Calendar of a month 7-9
4) Spiral matrix 10-14
5) Magic Number 15-18
6) Pascal’s triangle 19-21
7) Transpose Matrix 22-23
8) Encrypted String 24-27
9) Factorial of a number 28-29
10) Linear search 30-31
11) Binary search 32-34
12) Palindrome string 35-37
13) Bubble sort 38-40
14) Insertion sort 41-42
15) Decimal to Binary number 43-44
16) Slab rate 45-46
17) 2-D array 47-49
18) Chopping words 50-51
19) Record of data using 52-54
inheritance
20) Pop operation in stack 55-57
21) Replace vowels in string 58-59
22) Print Pattern 60-62
23) Convert Celsius to 63-64
Fahrenheit
24) Circular Queue 65-67
25) Combining different tables 68-73
using Inheritance
26) Bibliography 74
#PROGRAM 1:
Write a program to print all the numbers which have unique digits
within a given range (M and N).
For example:
For M=500 and N=513
Unique Digit Number: 501, 502, 503, 504, 506, 507, 508, 509, 510,
512
Frequency:10
For M=400 and N=380
The given range is not acceptable as M<N.
Algorithm :
STEP 1: Start
STEP 2: Declare instance variables M, N, freq.
STEP 3: Create a constructor Unique to input values for M and N
respectively and initialize freq with 0.
STEP 4: Create function printUnique and create an array in it and
print unique numbers.
STEP 5: Create isUnique function to check array and use it to see all
the digits in the number of the array are unique and return true or
false.
STEP 6: Create main to make object of printUnique and print
frequency.
STEP 7: STOP
STEP 8: END
SOURCE CODE:
import [Link].*;
class Unique
{
int M, N, freq;// instance variables for frequency and range
Unique()
{
Scanner sc=new Scanner([Link]);
[Link]("Please enter M: ");
M=[Link]();// input lower margin
[Link]("Please enter N: ");
N=[Link]();// input upper margin
freq=0;
}
void printUnique()
{
[Link]("All Unique Digit Numbers :");
int[] arr;// array to print all unique numbers
for(int i=M+1; i<N; i++)
{
arr=new int[10];
int num=i;
while(num!=0)
{
arr[num%10]++;
num/=10;
}
if(isUnique(arr))
{
[Link](i+" ");
freq++;
}}}
boolean isUnique(int[] arr)// check array and use it to see all the
digits in the number of the array are unique and return true or false
{
boolean ck=true; for(int i=0; i<10; i++)
if(arr[i]>1)
ck=false;
return ck;
}
public static void main(String args[])// main to call above functions
and print frequency
{
Unique obj=new Unique();
[Link]();
[Link]("\nFrequency: "+[Link]); }}
VDT
VARIABLE DATA TYPE DESCRIPTION
M int Lower boundary of
range
N int Upper boundary of
range
freq int Frequency of unique
numbers
arr int Array for checking
unique nos.
ck boolean Return true or false if
unique number or not
num int Separating each digit to
see if number is unique
or not
INPUT:
Please enter M:
23
Please enter N:
34
OUTPUT:
All Unique Digit Numbers :24 25 26 27 28 29 30 31 32
Frequency: 9
#PROGRAM 2:
Write a program to Display A.P. Series and Its Sum
A series with same common difference is known as arithmetic
series. The first term of series is a and common difference is d. The
series is looks like a, a + d, a + 2d, a + 3d, . . . Task is to find the sum
of series.
Examples:
Input : a = 1, d = 2
n=4
Output : 16
1 + 3 + 5 + 7 = 16
Input : a = 2.5
d = 1.5
n = 20
Output : 335
ALGORITHM:
STEP 1 - START
STEP 2 - a = d = 0
STEP 3 - IMPORT a, d
STEP 4 - this.a = a & this.d = d
STEP 5 - IMPORT n
STEP 6 - RETURN (a+(n-1)*d)
STEP 7 - IMPORT n
STEP 8 - RETURN (n*(a+nTHTerm(n))/2)
STEP 9 - IMPORT n
STEP 10 - PRINT \n\tSeries\n\t"
STEP 11 - IF i=1;i<=n;i++ GOTO STEP 12
STEP 12 - PRINT nTHTerm(i)+" "
STEP 13 - i++ & IF i<=n GOTO STEP 12
STEP 14 - PRINT n\tSum : "+Sum(n)
STEP 15 – END
SOURCE CODE:
class APSeries
{private double a,d;
APSeries() //default constructor
{a = d = 0;
}
APSeries(double a,double d) //parameterized constructor
{this.a = a; this.d = d;
}
double nTHTerm(int n) //final AP term
{return (a+(n-1)*d);
}
double Sum(int n) //function calculating sum
{return (n*(a+nTHTerm(n))/2);
}
void showSeries(int n)//displaying AP Series
{[Link]("\n\tSeries\n\t");
for(int i=1;i<=n;i++)
{[Link](nTHTerm(i)+" ");
}
[Link]("\n\tSum :"+Sum(n));
}
}
void main()throws IOException //main function
{BufferedReader br= new BufferedReader(new
InputStreamReader([Link])); [Link]("Enter 1st
term");
a=[Link]([Link]()); //accepting 1st term
[Link]("Enter Common difference");
d=[Link]([Link]()); //accepting common
difference [Link]("Enter [Link] terms");
int n=[Link]([Link]()); //accepting no. of terms
nTHTerm(n);
Sum(n); showSeries(n);
}
VDT
Name Type Description
a int 1st term
d int common difference
n int total terms
i int loop variable
OUTPUT
Enter 1st tern
12
Enter Common difference
23
Enter no. of terms
15
Series
12.0 35.0 58.0 81.0 104.0 127.0 150.0 173.0 196.0 219.0 242.0 265.0
288.0 311.0 334.0
Sum :2595.0
#PROGRAM 3:
Write a program to Display Calendar of Any Month of Any YEAR.
FOR EXAMPLE:
INPUT :
Enter month
7
Enter Year
1994
---------------------------------
July 1994
---------------------------------
SUN MON TUE WED THU FRI SAT
---------------------------------
1 2 3 4 5 6
---------------------------------
7 8 9 10 11 12 13
---------------------------------
14 15 16 17 18 19 20
---------------------------------
21 22 23 24 25 26 27
---------------------------------
28 29 30 31
---------------------------------
ALGORITHM
STEP 1 - START
STEP 2 - INPUT int month,int year
STEP 3 - int i,count=0,b,c,d=1 & String w="SMTWTFS"
STEP 4 - IF (year%100==0 && year%400==0) || (year%100!=0 &&
year%4==0) STEP 5 - days[1]=29
STEP 6 - PRINT "================The Calendar
of"+month1[month-1]+" "+year+"is==================")
STEP 7 - IF i=0 THEN GOTO STEP 8 STEP 8 - PRINT (i)+"\t" & " "
STEP 9 - IF i=1 GOTO STEP 10
STEP 10 - IF (year%100==0 && year%400==0) || (year%100!=0 &&
year%4==0)THEN GOTO STEP 11OTHERWISE GOTO STEP 12
STEP 11 - count+=2 STEP 12 - count+=1
STEP 13 - IF i=0 GOTO STEP 14
STEP 14 - count+=days[i] , count+=1, count%=7 & b=7-count STEP 15
- IF b!=1 || b!=7 GOTO STEP 16
STEP 16 - IF count>0 GOTO STEP 17,18 STEP 17 - PRINT ' '+"\t")
STEP 18 - count--
STEP 19 - IF i=1 GOTO STEP 20
STEP 20 - IF b>0 && IF d<=days[month-1] GOTO STEP 21,22 STEP 21 -
PRINT d+"\t"
STEP 22 - d++ & b-- STEP 23 - b=7
STEP 24 - i++ & IF i<MONTH GOTO STEP14 STEP 25 - PRINT " "
STEP 26 – END
SOURCE CODE:
import [Link].*;
class Calendar
{public void dee()throws IOException //dee() function
{int i,count=0,b,d=1;
BufferedReader br=new BufferedReader(new
InputStreamReader([Link])); [Link](“Enter month”);
//accepting month and year int
month=[Link]([Link]());
[Link](“Enter Year”);
int year=[Link]([Link]());
/* Computing and displaying calendar*/
String w="SMTWTFS";
int days[]={31,28,31,30,31,30,31,31,30,31,30,31};
Stringmonth1[]={"January","February","March","April","May","June"
,"July","August","September","October","November","December"};
if((year%100==0 && year%400==0) || (year%100!=0 &&
year%4==0)) days[1]=29;
[Link]("================The Calendar
of"+month1[month-1]+" "+year+"is==================");
for(i=0;i<[Link]();i++)
[Link]([Link](i)+"\t");
[Link](" "); for(i=1;i<year;i++)
if((year%100==0 && year%400==0) || (year%100!=0 &&
year%4==0))
count+=2;
else count+=1;
for(i=0;i<month;i++)
count+=days[i];
count+=1; count%=7;
b=7-count; if(b!=1 || b!=7) while(count>0)
{[Link](' '+"\t"); count--;
} for(i=1;i<7;i++)
{while(b>0 && d<=days[month-1])
{[Link](d+"\t"); d++;
b--;
} b=7;
[Link](" ");
}}}
VBT
Name Type Description
br BufferedRead BufferedReader object
er
i int loop variable
count int counter
b int week counter
d int day counter
month int input month
year int input year
w String week days
days String[] array storing days
month1 String[] array storing months
INPUT :
Enter month
2
Enter Year
2016
OUTPUT:
---------------------------------
February 2016
---------------------------------
SUN MON TUE WED THU FRI SAT
---------------------------------
1 2 3 4 5 6
---------------------------------
7 8 9 10 11 12 13
---------------------------------
14 15 16 17 18 19 20
---------------------------------
21 22 23 24 25 26 27
---------------------------------
28 29
--------------------------------
#PROGRAM 4:
Write a program to Display Spiral [Link] Spiral Matrix problem
takes a 2-Dimensional array of N-rows and M-columns as an input,
and prints the elements of this matrix in spiral order
ALGORITHM:
STEP 1 - START
STEP 2 - INPUT a[][]
STEP 3 - IF p!=(int)[Link](l,2) GOTO STEP
4 STEP 4 - IF co!=0 GOTO STEP 5
STEP 5 - re=1
STEP 6 - IF ri=1;ri<=k1-re;ri++ GOTO STEP 7
STEP 7 - p++,c++
STEP 8 - IF c==l GOTO STEP 9
STEP 9 - BREAK
STEP 10 - a[r][c]=p
STEP 11 - IF c==l GOTO STEP 12
STEP 12 - BREAK
STEP 13 - IF dw=1 GOTO STEP 14
STEP 14 - p++,r++,a[r][c]=p
STEP 15 - IF le=1 GOTO STEP 16
STEP 16 - p++,c--,a[r][c]=p
STEP 17 - IF up=1 GOTO STEP 18
STEP 18 - p++,r--,a[r][c]=p
STEP 19 - k1=k1+2, k2=k2+2 & co++
STEP 20 - up++ & IF up<=k2-1 GOTO STEP 18
STEP 21 - le++ & IF le<=k2-1 GOTO STEP 16
STEP 22 - dw++ & IF dw<=k1-1 GOTO STEP 14
STEP 23 - IF y=0 GOTO STEP 24
STEP 24 - IF yy=0 GOTO STEP 25
STEP 25 - PRINT "\t"+a[y][yy]) & ()
STEP 26 - yy++ & IF yy<l GOTO STEP 25
STEP 27 - y++ & IF y<l GOTO STEP 24
STEP 28 – END
SOURCE CODE:
import [Link].*;
class SpiralMatrix
{public static void main(String[] args) throws IOException //main
function
{int a[][],r,c,k1=2,k2=3,p=0,co=0,re=0;
BufferedReader br = new BufferedReader(new
InputStreamReader([Link])); [Link]("enter the
dimension of matrix A x A =");
int l = [Link]([Link]()); //accepting dimension of
square spiral matrix a=new int[l][l];
r=l/2;c=r-1; if(l%2==0)
{[Link]("wrong entry for spiral path"); [Link](0);}
/*Calculating and displaying spiral matrix*/
while(p!=(int)[Link](l,2))
{if(co!=0) re=1;for(int ri=1;ri<=k1-re;ri++)
{p++;c++;if(c==l)break;a[r][c]=p;} if(c==l)break;
for(int dw=1;dw<=k1-1;dw++)
{p++;r++;a[r][c]=p;} for(int le=1;le<=k2-1;le++)
{p++;c--;a[r][c]=p;}
for(int up=1;up<=k2-1;up++)
{p++;r--;a[r][c]=p;} k1=k1+2; k2=k2+2;
co++;}
for(int y=0;y<l;y++) //Displaying matrix
{for(int yy=0;yy<l;yy++)
[Link]("\t"+a[y][yy]);
[Link]();
[Link]();}}}
VBT
2|ISCComputerScienceProject
2
#PROGRAM 5:
Write a program to check the entered number is a Magic Number
or not. A Magic number is a number whose sum of its digits are
calculated till a single digit is obtained by recursively adding the
sum of its digits. If single digit obtained is 1, then the number is
magic number, otherwise not.
Example:
Number to check : 19
1 + 9 = 10 // 10 is not a single digit number, continue adding
digits
1+0=1 // 19 is a Magic number
ALGORITHM:
STEP 1- START
STEP 2-Initialize sumOfDigits variable value to 0. It will represent the
sum of digits of a given inputNumber.
STEP 3-Create a copy of the inputNumber (original number) by
storing its value in variable number.
STEP 4- Using while loop, continue the loop till the sumOfDigits does
not become a single digit or number is not equal to zero and get the
rightmost digit of variable number by using (number % 10) and add
its value to the variable sumOf Digits.
STEP 5-Check whether the variable sumOfDigits is equal to 1. If both
are equal then the inputNumber is Magic number. Otherwise,
the inputNumber is not a Magic number.
STEP 6-END
SOURCE CODE:
import [Link].*;
public class JavaHungry {
4|ISCComputerScienceProject
4
VDT
Output :
Enter any number : 145
145 is a Magic number
5|ISCComputerScienceProject
5
#PROGRAM 6:
Write a program to Create Pascal’s Triangle.
Pascal’s triangle is a triangular array of the binomial coefficients
that takes an integer value n as input and prints first n lines of the
Pascal’s triangle. For example: first 6 rows of Pascal’s Triangle.
1
11
121
1331
14641
1 5 10 10 5 1
ALGORITHM:
STEP 1 - START
STEP 2 - pas[0] = 1
STEP 3 - IF i=0 THEN GOTO STEP 4
STEP 4 - IF j=0 THEN GOTO STEP 5
STEP 5 - PRINT pas[j]+" "
STEP 6 - i++& IF i<n GOTO STEP 4
STEP 7 - j=0 & IF j<=i GOTO STEP 5
STEP 8 - IF j=i+1 THEN GOTO STEP 7
STEP 9 - pas[j]=pas[j]+pas[j-1]
STEP 10 - j--& IF j>0 GOTO STEP 9
STEP 11 – END
SOURCE CODE:
import [Link].*; class Pascal
{public void pascalw()throws IOException //pascalw() function
{BufferedReader br=new BufferedReader(new
InputStreamReader([Link])); [Link](“Enter a no.”);
6|ISCComputerScienceProject
6
int n=[Link]([Link]()); //accepting value int [ ] pas =
new int [n+1];
pas[0] = 1;
for (int i=0; i<n; i++) //loop evaluating the elements
{for (int j=0; j<=i; ++j)
[Link](pas[j]+" "); //printing the Pascal Triangle
elements [Link]( );
for (int j=i+1; j>0; j--) pas[j]=pas[j]+pas[j-1];}}}
VDT
Name Type Description
br BufferedReader BufferedReader object
n int Input value
pas int[] Matrix storing pascal
numbers
i int Loop variable
j int Loop variable
INPUT:
Enter a no.
7
OUTPUT:
1
11
121
1331
14641
1 5 10 10 5 1
1 6 15 20 15 6 1 7|ISCComputerScienceProject
7
#PROGRAM 7:
Write a program to enter an array and print the transpose of the
array. The transpose of a matrix is a new matrix that is obtained by
exchanging the rows and columns. In this program, the user is
asked to enter the number of rows r and columns c. Their values
should be less than 10 in this program. Then, the user is asked to
enter the elements of the matrix (of order r*c).
EXAMPLE:
Printing Matrix without transpose:
134
243
345
Printing Matrix After Transpose:
123
344
435
ALGORITHM:
STEP 1: Initialize array arr for 5x5 and declare 2 instance variables
m,n.
STEP 2: In constructor initialize instance variables with its given
parameters.
STEP 3: Create a function fillarray to input values for m,n.
STEP 4: Create a function to display the given array.
STEP 5: Create transpose function to assign the transpose array of
the given array.
STEP 6: Create a main function to use user defined datatypes to
create 2 arrays and get the transpose of the original array using the
above functions (through objects).
STEP 7: STOP
STEP 8: END
8|ISCComputerScienceProject
8
SOURCE CODE:
import [Link]; class TransArray
{
public static void main(String args[])// main to create objects of
functions and call them
{
TransArray A=new TransArray(5,10), B=new TransArray(5,10);
[Link]();
[Link]();
[Link](A);
[Link]();
}
int[][] arr=new int[5][5]; //instance variables int m,n;
TransArray(int m, int n) // constructor to initialize instance variables
{
this.m=m;
this.n=n;
}
void fillArray()// input values for array
{
Scanner sc=new Scanner([Link]); for(int i=0; i<m; i++)
{
for(int j=0; j<n; j++)
{
[Link]("Please enter value at:
"+m+"*"+n);
arr[i][j]=[Link]();
}
}
}
void show()
{
for(int i=0; i<m; i++)
9|ISCComputerScienceProject
9
{
for(int j=0; j<n; j++)
[Link](arr[i][j]+"");// print the array
[Link]();
}
}
void transpose(TransArray A)// function to assign transpose of given
array
{
for(int i=0; i<A.m; i++)
{
for(int j=0; j<A.n; j++)
[Link][i][j]=[Link][i][j];
}
}}
VDT
VARIABLE DATA TYPE DESCRIPTION
arr int Array of dimensions
5x5
m int Row of array
n int Column of array
i int looping
j int looping
sc int Scanner for input
INPUT:
Enter rows and columns: 2
3
Enter matrix elements: Enter element a11: 1
Enter element a12: 4
Enter element a13: 0
Enter element a21: -5
10 | I S C C o m p u t e r S c i e n c e P r o j e c t
10
Enter element a22: 2
Enter element a23: 7
OUTPUT:
Entered matrix:
1 4 0
-5 2 7
11 | I S C C o m p u t e r S c i e n c e P r o j e c t
11
#PROGRAM 8:
Write a program to encrypt the given string using following rules
and return the encrypted string:
• Replace the characters at odd positions by next character in
the alphabet.
• Leave the characters at even positions unchanged.
Algorithm :
STEP 1: Start
STEP 2: Create a main function and input a sentence and print the
encrypted sentence through the function stringFormatting.
STEP 3: Create function stringFormatting to encrypt the inputted
sentence and return it to the main.
STEP 4: STOP
STEP 5: END
Source Code:
import [Link];
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner([Link]);
[Link](“enter sentence”);
String s1 = [Link](); // input sentence
[Link](stringFormatting(s1));//print encrypted sentence
}
public static String stringFormatting(String s1)
{
StringBuffer sb=new StringBuffer();
for(int i=0;i<[Link]();i++)
{
12 | I S C C o m p u t e r S c i e n c e P r o j e c t
12
char c=[Link](i); //getting each character of the given string
if(i%2==0)// encrypting each letter
{
if(c==122)
c=(char) (c-25);
else{
c=(char) (c+1);}
[Link](c);}
else
[Link](c);}
return [Link]();//returning encrypted string
}
}
VDT
VARIABLE DATA TYPE DESCRIPTION
S1 String Input sentence
c char Each character of sentence
i int looping
Input 1:
Curiosity
Output
1:
dusipsjtz
13 | I S C C o m p u t e r S c i e n c e P r o j e c t
13
#PROGRAM 9:
Write a program to Calculate Factorial Using Recursion
Factorial Program in Java: Factorial of n is the product of all positive
descending integers. Factorial of n is denoted by n!. For example:
4! = 4*3*2*1 = 24
5! = 5*4*3*2*1 = 120
ALGORITHM:
STEP 1 - START
STEP 2 - INPUT n
STEP 3 - IF(n<2) THEN return 1 OTHERWISE return (n * fact(n-1))
STEP 4 – END
SOURCE CODE:
import [Link].*;
class Factorial
{public static void main(String args[]) throws IOException //main
function
{BufferedReader br = new BufferedReader(new
InputStreamReader([Link])); [Link]("enter no =");
int n = [Link]([Link]()); //accepting no. Factorial obj =
new Factorial();
long f = [Link](n);
14 | I S C C o m p u t e r S c i e n c e P r o j e c t
14
[Link]("Factorial ="+f); //displaying factorial
}
public long fact(int n) //recursive fact()
{if(n<2) return 1;
else return (n*fact(n-1));
}}
VDT
Name Type Description
br BufferedReader BufferedReader object
n int input number
obj Factorial Factorial object
f long variable storing factorial
n int parameter in recursive function
fact()
OUTPUT:
Enter no =
12
Factorial = 479001600
15 | I S C C o m p u t e r S c i e n c e P r o j e c t
15
#PROGRAM 10:
Write a program to Search an Array Using Linear Search
Linear search is used to search a key element from multiple
elements.
ALGORITHM:
STEP 1 – START
STEP 2 - INPUT a[]
STEP 3 - FROM i=0 to i<n REPEAT STEP 4
STEP 4 - PRINT a[i]+" "
STEP 5 - flag=-1
STEP 6 - FROM i=0 to i<n REPEAT STEP 7
STEP 7 - IF (a[i] == v) THEN flag =i
STEP 8 - IF (flag=-1) THEN GOTO STEP 9 OTHERWISE GOTO STEP 10
STEP 9 - PRINT “ not found”
STEP 10 - PRINT v+" found at position - "+flag
STEP 11 – END
SOURCE CODE:
import [Link].*;
class LinearSearch
{int n,i;
int a[] = new int[100];
static BufferedReader br =new BufferedReader(new
InputStreamReader([Link])); public LinearSearch(int nn)
{n=nn;
}
public void input() throws IOException //function for obtaining
values from user
{[Link]("enter elements"); for(i=0;i<n;i++)
{a[i] = [Link]([Link]());
}}
16 | I S C C o m p u t e r S c i e n c e P r o j e c t
16
public void display() //function displaying array values
{[Link](); for(i=0;i<n;i++)
{[Link](a[i]+" ");
}}
public void search(int v) //linear search function
{int flag=-1;
for(int i=0; i<n ; i++)
{if(a[i] == v) flag =i;
}
if(flag== -1 ) [Link]("not found");
else [Link](v+" found at position - "+flag);
}
public static void main(String args[]) throws IOException //main
function
{LinearSearch obj = new LinearSearch(10); [Link]();
[Link]();
[Link]("enter no. to be searched -"); //accepting the
values to be searched int v = [Link]([Link]());
[Link](v);
}}
VDT
18 | I S C C o m p u t e r S c i e n c e P r o j e c t
18
#PROGRAM 11:
Write a program to Search an Array Using Binary Search.
In case of binary search, array elements must be in ascending
order. If you have unsorted array, you can sort the array.
ALGORITHM:
SOURCE CODE:
Import [Link].*;
class BinarySearch
{int n,i;
Int a[] = new int[100];
Static BufferedReader br =new BufferedReader(new
InputStreamReader([Link])); public BinarySearch(int nn)
//default constructor
{n=nn;
}
19 | I S C C o m p u t e r S c i e n c e P r o j e c t
19
Public void input() throws IOException //function accepting array
elements
{[Link](“enter elements”); for(i=0;i<n;i++)
{a[i] = [Link]([Link]());
}}
Public void display() //displaying array elements
{[Link](); for(i=0;i<n;i++)
{[Link](a[i]+” “);
}}
Public void search(int v) //function to search array elements using
binary search technique
{int l=0; int u = n-1; int m;
Int flag=-1;
While( l<=u && flag == -1)
{m = (l+u)/2;
If(a[m] == v) flag = m;
Else if(a[m] < v) l = m+1;
Else u = m-1;
}
If(flag== -1 ) [Link](“not found”);
Else [Link](v+” found at position – “+flag);}
Public static void main(String args[]) throws IOException //main
function
{
BinarySearch obj = new BinarySearch(10); [Link]();
[Link]();
[Link](“enter no. To be searched –“);
Int v = [Link]([Link]()); //accepting integer to be
searched by binary search [Link](v);
}}
20 | I S C C o m p u t e r S c i e n c e P r o j e c t
20
VDT
Name Type Description
br BufferedReader BufferedReader object
n int array length
i int loop variable
a[] int[] input array
nn int parameter in constructor
v int search element
flag int flag
l int lower limit
u int upper limit
m int middle index
obj BinarySearch BinarySearch object
OUTPUT:
Enter elements
12
90
67
45
76
44
45
143
987
099
21 | I S C C o m p u t e r S c i e n c e P r o j e c t
21
#PROGRAM 12:
Write a program to Check if Entered String is Palindrome or not.
A palindromic number is a number that remains the same when its
digits are reversed.
For example 121, 34543, 343, 131, 48984 are the palindrome
numbers.
ALGORITHM
STEP 1 - START
STEP 2 - INPUT string s STEP 3 - StringBuffer sb = s STEP 4 - [Link]
STEP 5 - String rev = sb
STEP 6 - IF rev = s GOTO STEP 7 OTHERWISE GOTO STEP 8
STEP 7 - PRINT " Palindrome" STEP 8 - PRINT " Not Palindrome"
STEP 9 – END
SOURCE CODE:
import [Link].*;
class Palindrome
{public static void main(String args[]) throws IOException //main
function
{BufferedReader br = new BufferedReader(new
InputStreamReader([Link])); [Link]("enter the
string=");
String s = [Link](); //accepting the string StringBuffer sb =
new StringBuffer(s);
[Link](); //reversing the string String rev = new String(sb);
if([Link](rev)) //checking for palindrome
[Link]("Palindrome " ); //displaying the result
else [Link]("Not Palindrome " );
}}
22 | I S C C o m p u t e r S c i e n c e P r o j e c t
22
VDT
Name Type Description
br BufferedReader BufferedReader object
s String input string
sb StringBuffer StringBuffer object of s
rev String revese string
OUTPUT:
Enter the string=
MADAM
Palindrome
23 | I S C C o m p u t e r S c i e n c e P r o j e c t
23
#PROGRAM 13:
Write a program to Sort an Array Using Bubble Sort. Bubble Sort is
the simplest sorting algorithm that works by repeatedly swapping
the adjacent elements if they are in wrong order.
ALGORITHM:
STEP 1 - START
STEP 2 - INPUT a[]
STEP 3 - FROM i=0 to i<n REPEAT STEP 4
STEP 4 - PRINT a[i]+" "
STEP 5 - flag=-1
STEP 6 - FROM i=0 to i<n-1 REPEAT STEP 7 to STEP 9
STEP 7 - FROM j=i+1 to j<n REPEAT STEP 8
STEP 8 - IF(a[j] > a[j+1]) THEN GOTO STEP 9
STEP 9 - temp = a[i], a[i] =a[min], a[min] = temp
STEP 10 - END
SOURCE CODE:
import [Link].*;
class BubbleSort
{int n,i;
int a[] = new int[100];
public BubbleSort(int nn) //parameterized constructor
{n=nn;
}
public void input() throws IOException //function accepting array
elements
{BufferedReader br =new BufferedReader(new
InputStreamReader([Link])); [Link]("enter
elements");
for(i=0;i<n;i++)
24 | I S C C o m p u t e r S c i e n c e P r o j e c t
24
{a[i] = [Link]([Link]());
}}
public void display() //function displaying array elements
{[Link](); for(i=0;i<n;i++)
{[Link](a[i]+" ");
}}
public void sort() //function sorting array elements using Bubble
Sort technique
{int j,temp;
for(i=0 ; i<n-1 ; i++)
{for(j=0 ; j<n-1-i ; j++)
{if(a[j] > a[j+1])
{temp = a[j];
a[j] =a[j+1]; a[j+1] = temp;
}}}}
public static void main(String args[]) throws IOException //main
function
{BubbleSort x = new BubbleSort(5); [Link]();
[Link]("Before sorting - "); [Link]();
[Link]("After sorting - "); [Link]();
[Link]();}}
VDT
Name Type Description
br BufferedReader BufferedReader object
n into array length
i int loop variable
a[] int[] input array
nn int parameter in constructor
j int sort index
temp int temporary storage
x SelectionSort SelectionSort object
25 | I S C C o m p u t e r S c i e n c e P r o j e c t
25
OUTPUT
enter elements
21
234
54
56
23
Before sorting
21 234 54 56 23
After sorting
21 23 54 56 234
26 | I S C C o m p u t e r S c i e n c e P r o j e c t
26
#PROGRAM 14:
Write a program to Sort an Array Using Insertion Sort. The array is
virtually split into a sorted and an unsorted part. Values from the
unsorted part are picked and placed at the correct position in the
sorted part.
ALGORITHM:
STEP 1: START
STEP 2: insertionSort(array)
STEP 3: mark first element as sorted
STEP 4: for each unsorted element X
STEP 5: extract' the element X
STEP 6: for j <- lastSortedIndex down to 0
STEP 7: if current element j > X
STEP 8: above sorted element to the right by 1
STEP 9: break loop and insert X here
STEP 10: END
SOURCE CODE:
public class InsertionSortExample {
public static void insertionSort(int array[]) {
int n = [Link];
for (int j = 1; j < n; j++) {
int key = array[j];
int i = j-1;
while ( (i > -1) && ( array [i] > key ) ) {
array [i+1] = array [i];
i--;
}
array[i+1] = key;
}
27 | I S C C o m p u t e r S c i e n c e P r o j e c t
27
} public static void main(String a[]){
int[] arr1 = {9,14,3,2,43,11,58,22};
[Link]("Before Insertion Sort");
for(int i:arr1){
[Link](i+" ");
}
[Link]();
insertionSort(arr1);//sorting array using insertion sort
[Link]("After Insertion Sort");
for(int i:arr1){
[Link](i+" ");
}
}
}
VBT
Name Type Description
n Int Array length
i int Looping
j int Looping
key int Intermediate in loop
Array[] Int[] Input array
OUTPUT:
Before Insertion Sort
9 14 3 2 43 11 58 22
After Insertion Sort
2 3 9 11 14 22 43 58
28 | I S C C o m p u t e r S c i e n c e P r o j e c t
28
#PROGRAM 15:
Write a program to Convert a Decimal no. Into its Binary
Equivalent. Example − Convert decimal number 125 into binary
number. Binary Number=1111101.
ALGORITHM:
STEP 1 - START STEP 2 - n = 30
STEP 3 - INPUT int no STEP 4 - c =0 , temp = no
STEP 5 - IF (temp!=0) REPEAT STEP 6
STEP 6 - a[c++] = temp%2, temp = temp / 2 STEP 7 - FROM i=c-1 to
i>0 REPEAT STEP 8 STEP 8 - PRINT a[i]
STEP 9 – END
SOURCE CODE:
import [Link].*;
class Dec2Bin
{int n,i;
int a[] = new int[100];
static BufferedReader br =new BufferedReader(new
InputStreamReader([Link]));
public Dec2Bin(int nn)//parameterized contructor
{n=nn;
}
public void dectobin(int no) //function converting decimalto binary
number
{int c = 0;
int temp = no; while(temp != 0)
{a[c++] = temp % 2; temp = temp / 2;
}
[Link]("Binary eq. of "+no+" = ");
for( i = c-1 ; i>=0 ; i--) //Displaying binary number [Link](
a[ i ] );
29 | I S C C o m p u t e r S c i e n c e P r o j e c t
29
}
public static void main(String args[]) throws IOException //main
function
{Dec2Bin obj = new Dec2Bin(30);
[Link]("enter decimal no -");
int no = [Link]([Link]());
[Link](no);
}}
VDT
Name Type Description
br BufferedReader BufferedReader object
n int array length
i int loop variable
a[] int[] array storing binary no.
nn int parameter in
constructor
no int input number
temp int temporary storage
c int counter
obj Dec2Bin Dec2Bin object
OUTPUT
enter decimal no-
56
Binary eq. of 56 =
111000
30 | I S C C o m p u t e r S c i e n c e P r o j e c t
30
#PROGRAM 16:
To Calculate the Commission
of a Salesman as per the Following Data
Sales Commission
>=100000 25% of sales
80000-99999 22.5% of sales
60000-79999 20% of sales
40000-59999 15% of sales
<40000 12.5% of sales
ALGORITHM:
STEP 1 - START
STEP 2 - INPUT sales
STEP 3 - IF (sales>=100000) THEN comm=0.25 *sales OTHERWISE
GOTO STEP 4 STEP 4 - IF (sales>=80000) THEN comm=0.225*sales
OTHERWISE GOTO STEP 5 STEP 5 - IF (sales>=60000) THEN
comm=0.2 *sales OTHERWISE GOTO STEP 6 STEP 6 - IF
(sales>=40000) THEN comm=0.15 *sales OTHERWISE GOTO STEP 7
STEP 7 - comm=0.125*sales
STEP 8 - PRINT "Commission of the employee="+comm
STEP 9 – END
SOURCE CODE:
import [Link].*;
class SalesComission
{public static void main(String args[])throws IOException //main
function
{double sales,comm;
BufferedReader aa=new BufferedReader(new
InputStreamReader([Link])); [Link](“Enter sales”);
31 | I S C C o m p u t e r S c i e n c e P r o j e c t
31
sales=[Link]([Link]()); //reading sales from the
keyboard
/*calculating commission*/
if(sales>=100000) comm=0.25*sales;
else if(sales>=80000) comm=0.225*sales;
else if(sales>=60000) comm=0.2*sales;
else if(sales>=40000) comm=0.15*sales;
else comm=0.125*sales;
[Link]("Commission of the employee="+comm);
//displaying commission
}}
VDT
Name Type Description
aa BufferedReader BufferedReader
object
sales double sales
comm. double commision
OUTPUT
Enter sales
2130000
Commission of the employee=532500.0
32 | I S C C o m p u t e r S c i e n c e P r o j e c t
32
#PROGRAM 17:
Write a program to input a 2-D of size 3x3 array and print its
Mirror Array along with it.
For example:
For an array:{{1,2,3},{4,5,6},{7,8,9}} should give the following
output:
123 321
456 654
789 987
ALGORITHM:
STEP 1: Start
STEP 2: Initialize Array arr to make array of 3x3 dimensions.
STEP 3: Create a constructor to input values for 2-D array. Through
outer loop (i.e for i) control row inputs and through inner loop (i.e
for j) control column inputs.
STEP 4: Construct a display function to display the original array and
mirror array. Through outer loop(i.e i) control row of array, through
inner loop(i.e j) first print elements of original array then after ten
spaces print elements of mirror array.
STEP 5: Repeat step 4 for next 3 rows.
STEP 6: Make a main function to call the above functions.
STEP 7: STOP
STEP 8: END
SOURCE CODE:
import [Link];
class MirrorArray
{
int[][] arr=new int[3][3]; // Initialize Array arr to make array of 3x3
dimensions.
MirrorArray()//a constructor to input values33 | I S Cfor
C o 2-D
m p u array
terScienceProject
33
{
Scanner sc=new Scanner([Link]);
for(int i=0 ; i<3 ; i++)//loop to control rows of array
{for(int j=0; j<3; j++)//loop to control columns of
array
{
[Link]("Please enter value for matrix"+i+"*"+j);
arr[i][j]=[Link]();
}
}
void displayMirror()//display the original array and mirror array
{ for(int i=0; i<3; i++)// control row of array
{
for(int j=0; j<3; j++)//first print elements of
originalarray
[Link](arr[i][j]+"");
[Link]("\t");
34 | I S C C o m p u t e r S c i e n c e P r o j e c t
34
VDT
VARIABLE DATA TYPE DESCRIPTION
arr int Array of dimension 3x3
i int For looping
sc int Input through scanner
j int For looping
INPUT: OUTPUT:
1 123 321
2 456 654
3 789 987
4
5
6
7
8
9
35 | I S C C o m p u t e r S c i e n c e P r o j e c t
35
#PROGRAM 18:
Write a program to input a String and remove the first and the last
character of each word and print joining the resultant words into 1
sentence. If a word contains only two letters then it is completely
removed.
ALGORITHM:
STEP 1: Start
STEP 2: Create a function rmChar to remove the first and last character of the
parameterized word.
STEP 3: Create a main to input a sentence and count the number of words in the
given sentence and make a loop for sending each word in the function rmChar.
Then add the returned words into 1 sentence
STEP 4: Print the original string and the new string.
STEP 5: STOP
STEP 6: END
SOURCE CODE:
import [Link].*;
class Modify
{
public static String rmChar(String wrd)
{ int len=[Link]();//to get length of word
if(len<=2)
return "";
else
{String fn=[Link](1, len-1);//remove first and last
Character of each word
return fn+""; }
}public static void main(String args[])
{
Scanner sc=new Scanner([Link]);
String inp="", mod="";
36 | I S C C o m p u t e r S c i e n c e P r o j e c t
36
[Link]("Please enter the sentence: ");//inputting
sentence inp=[Link]();
StringTokenizer st=new StringTokenizer(inp);
int words=[Link]();//count number of words in sentence
for(int i=0; i<words; i++)
{String wrd=[Link]();//getting each word
mod=mod+rmChar(wrd);//adding each modified
word in 1 sentence
}
[Link]("Original String: "+inp);//print
original string
[Link]("Modified String: "+mod);//print
modified string
}
}
VDT
VARIABLE DATA TYPE DESCRIPTION
inp String Input sentence
mod String To assemble modified
words in 1 sentence
wrd String Each word of sentence
len int Length of word
fn String Modified word
i int looping
INPUT:
Please enter the sentence:
I STUDY IN CMS
OUTPUT:
Original String: I STUDY IN CMS
Modified String: TUDM
37 | I S C C o m p u t e r S c i e n c e P r o j e c t
37
#PROGRAM 19:
A super class Record contains names and marks of the students in
two different single dimensional arrays. Define a sub class Highest
to display the names of the students obtaining
the highest mark.
The details of the members of both the classes are given below:
Class name : Record
Data member/instance variable:
n[ ] : array to store names
m[ ] : array to store marks
size : to store the number of students
Member functions/methods:
Record(int cap) : parameterized constructor to initialize the data
member size = cap
void readarray() : to enter elements in both the arrays
void display( ) : displays the array elements
Class name: Highest
Data member/instance variable:
ind : to store the index
Member functions/methods:
Highest(…) : parameterized constructor to initialize the data
members of both the classes
void find( ) : finds the index of the student obtaining the
highest mark and assign it to ‘ind’
void display( ) : displays the array elements along with the names
and marks of the students who have obtained the
highest mark
Assume that the super class Record has been defined. Using the
concept of inheritance,
specify the class Highest giving the details of the
constructor(…),void find( ) and
void display( )
38 | I S C C o m p u t e r S c i e n c e P r o j e c t
38
ALGORITHM:
STEP 1: START
STEP 2: As it’s an extended class, specify that it’s extends record
class.
STEP 3: Ind variable is used to store index of the searched data.
STEP 4: Make a parameterized constructor to initialize the data
members of both the classes.
STEP 5: Then make a class void find() which displays the array
elements along with the names and marks of the students who have
obtained the highest marks.
STEP 6: END
SOURCE CODE:
import [Link].*;
class Highest extends Record
{ int ind;
Highest(int cap)
{ super(cap);
ind=-1;
}
void find()
{ readarray();
int hm=m[0];
for (int i=0;i<size;i++)
{ if (m[i]>hm)
{ hm=m[i];
ind=i;
}}}
void display()
{ [Link]();
for(int i=0;i<size;i++)
{ if(m[i]==m[ind])
[Link]("Highest obtained by "+n[i] + " marks "+m[i]);
39 | I S C C o m p u t e r S c i e n c e P r o j e c t
39
}
}
}
VDT
OUTPUT
Highest obtained by Sarthak Chaudhavarsh marks 100.
40 | I S C C o m p u t e r S c i e n c e P r o j e c t
40
#PROGRAM 20:
Write a program for to take out elements from a stack (Pop
operation). Pop operation used to pop an element from the stack.
The element is popped from the top of the stack and is removed
from the same.
ALGORITHM:
STEP 1: START
STEP 2: A pointer called TOP is used to keep track of the top element
in the stack.
STEP 3: When initializing the stack, we set its value to -1 so that we
can check if the stack is empty by comparing TOP == -1.
STEP 4: On pushing an element, we increase the value of TOP and
place the new element in the position pointed to by TOP.
STEP 5: On popping an element, we return the element pointed to
by TOP and reduce its value.
STEP 6: Before pushing, we check if the stack is already full
STEP 7: Before popping, we check if the stack is already empty
STEP 8: END
SOURCE CODE:
// Java program to implement above approach
import [Link];
import [Link];
class GFG
{ // Function to find the count
public static void countEle(Stack<Integer> s,
int[] a, int N)
41 | I S C C o m p u t e r S c i e n c e P r o j e c t
41
{
// Hashmap to store all the elements
// which are popped once.
HashMap<Integer,
Boolean> mp = new HashMap<>();
for (int i = 0; i < N; ++i)
{ int num = a[i];
// Check if the number is present
// in the hashmap Or in other words
// been popped out from the stack before.
if ([Link](num))
[Link]("0 ");
else
{
int cnt = 0;
// Keep popping the elements
// while top is not equal to num
while ([Link]() != num)
{ [Link]([Link](), true);
[Link]();
cnt++;
} // Pop the top ie. equal to num
[Link]();
cnt++;
// Print the number of elements popped.
[Link](cnt + " ");
}
}
}// Driver code
public static void main(String[] args)
{ int N = 5;
Stack<Integer> s = new Stack<>();
[Link](1);
[Link](2);
42 | I S C C o m p u t e r S c i e n c e P r o j e c t
42
[Link](3);
[Link](4);
[Link](6);
int[] a = { 6, 3, 4, 1, 2 };
countEle(s, a, N);
}}
VDT
VARIABLE DATA TYPE DESCRIPTION
N int Size of stack
i Int Looping
Output:
Initial Stack: [Welcome, To, Geeks, For, Geeks]
Popped element: Geeks
Popped element: For
Stack after pop peration [Welcome, To, Geeks]
43 | I S C C o m p u t e r S c i e n c e P r o j e c t
43
#PROGRAM 21:
Write a program to create a string and replace all vowels with *.
For Example:
Input : what is your name ?
Output : wh*t *s y**r n*m* ?
ALGORITHM:
STEP 1 - START
STEP 2 - a = "Computer Applications" STEP 3 - x= 0
STEP 4 - FROM z =0 to z<[Link]() REPEAT STEP 5
STEP 5 -
if([Link](z)=='a'||[Link](z)=='e'||[Link](z)=='i'||[Link](z)=='
o'||[Link](z)=='u’) THEN [Link](z,'*')
STEP 6 - PRINT "New String -"+a
STEP 7 – END
SOURCE CODE:
import [Link].*;
class VowelReplace
{public static void main(String args[])throws IOException //main
function
{BufferedReader br=new BufferedReader(new
InputStreamReader([Link])); [Link](“Enter a String”);
StringBuffer a=new StringBuffer([Link]()); //accepting a string
[Link]("Original String -"+a);
int z=0;
44 | I S C C o m p u t e r S c i e n c e P r o j e c t
44
for(z=0;z<[Link]();z++) //loop for replacing vowels with "*"
{if([Link](z)=='a'||[Link](z)=='e'||[Link](z)=='i'||[Link](z)==
'o'||[Link](z)=='u') [Link](z,'*');
}
[Link]("New String -"+a); //displaying the result
}}
VDT
Name Type Description
br BufferedReader BufferedReader object
a StringBuffer StringBuffer object of input
string
z int loop variable
Output
Enter a string: Ram bought apple and umbrella in a big shop
Ram bought apple and umbrella in a big shop
R*m b**ght *ppl* *nd *mbr*ll* *n * b*g sh*p
45 | I S C C o m p u t e r S c i e n c e P r o j e c t
45
#PROGRAM 22:
Write a program that will print the following pattern:
For input = 4
*
**
* *
* * *
The pattern should be printed in a row wise manner.
ALGORITHM:
STEP 1: START
STEP 2: take input for number of rows (height of triangle)
STEP 3: make double loops for the formation of triangle. Outer loop
for rows and inner loop for columns.
STEP 4: after that make another loop for elimination of stars within
the perimeter to make it hollow.
STEP 5:
SOURCE CODE:
import [Link];
public class Program
{
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
// Taking Input
[Link]("Enter the Number:");
int n = [Link]();
[Link]();
// No. of spaces between the stars
int k = 0;
// Printing Pattern
for (int i = 0; i < n; i++){
// First row have only one star
46 | I S C C o m p u t e r S c i e n c e P r o j e c t
46
if (i == 0){
[Link]("* ");
}
// For last row
else if (i == (n - 1)){
for (int j = 0; j < n; j++){
[Link]("* ");
}
}
// Other conditions
else{
[Link]("* ");
for (int m = 0; m< k; m++){
[Link](" ");
}
[Link]("* ");
k += 2;
}
[Link]();
}
}
}
VDT
VARIABLE DATA TYPE DESCRIPTION
n int Take input of
number of rows
k int Number of spaces
in the triangle
i int Outer loop
j int Inner loop
47 | I S C C o m p u t e r S c i e n c e P r o j e c t
47
OUTPUT
Enter the number: 5
*
**
* *
* *
*****
48 | I S C C o m p u t e r S c i e n c e P r o j e c t
48
#PROGRAM 23:
Write a program to Convert Celsius into Fahrenheit Using
Inheritance. Take input value in Celsius and convert it to
Fahrenheit. The formula to convert Fahrenheit into Celsius:
F= C*(9/5) +32
ALGORITHM
STEP 1 – START
STEP 2 -- Input temperature ‘celcius’ in celcius
STEP 3 – far=1.8*celcius + 32
STEP 4 – Display far
STEP 5 -- END
SOURCE CODE:
import [Link].*;
class C2F
{ public static void main(String args[])throws IOException //main
function
{Temperature ob= new Temperature();
BufferedReader br=new BufferedReader(new
InputStreamReader([Link]));
[Link]("Enter temperature in Celsius"); //accepting
temperature double
temp=[Link]([Link]([Link]()));
[Link]("The temperature in fahrenheit is = "+temp);
}}
class Temperature extends C2F
{double convert(double celcius) //function to convert Celsius to
fahrenheit
{double far=1.8*celcius+32.0; return far;
}}
49 | I S C C o m p u t e r S c i e n c e P r o j e c t
49
VBT
Name Type Description
br BufferedReader BufferedReader object
ob C2F C2F object
temp double calculated Fahrenheit
temperature
celcius double input temperature in Celsius
far double Calculated Fahrenheit
temperature
OUTPUT
Enter temperature in Celsius
67
The temperature in Fahrenheit is = 152.60000000002
50 | I S C C o m p u t e r S c i e n c e P r o j e c t
50
#PROGRAM 24:
Write a program to input values and put it in a Circular Queue. A
Circular Queue is a linear data structure which works on the principle
of FIFO, enables the user to enter data from the rear end and remove
data from the front end with the rear end connected to the front end
to form a circular pattern.
Algorithm
STEP 1: START
STEP 2: To insert item /* Queue – ar[], pointer – rear,front*/
STEP 3: Check for overflow
STEP 4: Set the pointers
STEP 5: Insert the item
STEP 6: To delete item Check for underflow
STEP 7: Delete an item
STEP 8: Set the pointers
STEP 9: For Display() for i=0 to size-1
STEP 10: Display ar[i]
STEP 11: END
PROGRAM CODE:
import [Link].*;
class Circular_Queue{
int size=5, front=-1, rear=-1;
int ar[{J= new int[size];
51 | I S C C o m p u t e r S c i e n c e P r o j e c t
51
void delete_queue()//delete element function
{ if (front==-1 ¢& rear==-1)//checking if queue is empty
[Link] ("Queue Underflow");
else
{ [Link] ("Deleted- |"“tar[front]+"| “)?
if (front==size-1)
front=0;
else if (front==rear)
front=rear=-1;
else
frontt++;} }
void rear_insert(int n)//insert element function
{ if ((front==0 && rear==size-1) || (front==reart1) )
[Link] ("Queue overflow. Delete elements");
else{
if (front==-1 && rear==-1)
front=rear=0;
else if (rear==size-1)
rear=0;
else
rear++;
ar[rear]=n;
52 | I S C C o m p u t e r S c i e n c e P r o j e c t
52
}}
void display()//Gisolay queue function
{ for(int i=0;i<size;i++)
[Link]("|"+ar[i]+"| ");
}}
VBT
Name Type Description
size int Size of array
front int To move in the queue from front
rear int To move in the queue from back
ar[] int Array inputted
Output:
|1|
|2|
|3|
|4|
|5|
Deleted Element: - |1|
|6|
|2|
|3|
|4|
|5|
53 | I S C C o m p u t e r S c i e n c e P r o j e c t
53
#PROGRAM 25:
A class "Teacher" defines the related information such as name, date
of birth and the date of joining while another class "Principal" defines
the different functions to display the relative information about the
teachers. The details of both the classes are given below:
(1) Specify the class Teacher giving the details of functions void
getdata() and void show getdata().
54 | I S C C o m p u t e r S c i e n c e P r o j e c t
54
(2).Using concept of inheritance, specify the class Principal giving the
details of function void sort data(), void display() and void search
data(). Class Principal is derived from class Teacher.
ALGORITHM:
STEP 1: START
STEP 2: Initialize data members of teacher class.
STEP 3: Get input for details of teachers.
STEP 4: Show the data with suitable headings.
STEP 5: Sort the arrays based on alphabetical order of names using
bubble sort in class principal.
STEP 6: Display the sorted list with all the data members with suitable
headings.
STEP 7: To input the name of a teacher and search for it using
sequential search technique. If found, print the details of the searched
item, otherwise print an appropriate message.
STEP 8: END
SOURCE CODE:
// code written in base class
import [Link].*;
class Teacher
{
String names[ ] = new String[50];
String dob[] = new String[50];
String doj[]= new String[50];
void getdata()//To input the values of all the data members.
{
Scanner in= new Scanner([Link]);
int i;
for(i=0;i<50;i++).
{
[Link]("Enter name in the cell "+ (i + 1) + ":");
55 | I S C C o m p u t e r S c i e n c e P r o j e c t
55
name[i] = [Link]();
[Link]("Enter date of birth in the cell "+ (i + 1) + ":");
dob[i] = [Link]();
[Link]("Enter data of joining in the cell "+ (i + 1) + ": ");
dojli] = [Link]();
}}
void showgetdata()
{ int I;
[Link](“The names with date of birth and date of joining
are:”) ;
for(i=0;i<50;i++)
[Link](name[i] + “\t\t” + dob[i] + “\t\t” + doj[i]);
}}
// end of base class
// code written in derived class
import [Link].*;
class Principal extends Teacher
{
int i, j;
String temp,t1,t2;
void sortdata() //To sort the array based on alphabetical order of
names using the bubble sort technique.
{
for(i=0;i<49;i++)
{
for(j=0;j<(49-i);j++)
{
if(name[j].compareTo(name[j+1])>0)
{ temp=name[j];name[j] = name[j+1];name[j+1] = temp;
t1= dob[j]; dob[j] = dob[j+1]; dob[j+1]=t1;
t2= doj[j]; doj[j] = doj[j+1]; doj[j+1]=t2;
}}}}
56 | I S C C o m p u t e r S c i e n c e P r o j e c t
56
void display()//To display the sorted list of all the data members with
suitable headings.
{
[Link](“Names with date of birth and date of joining are:”);
for(j=0;j<50;j++)
[Link](name[j]+ “\t\t” + dob[j] + “\t\t” + doj[j]);
}
void searchdata()
{
Scanner in= new Scanner([Link]);
int i;
String n;
[Link](“Enter the name to be searched:”);
n=[Link]();
for(i=0;i<50;i++)
{if([Link](name[i]))
{
[Link]("Name is present and the details are:");
[Link](name[i] + "\t\t" + dob[i] + "\t\t" + doj[j]);
break;
}
else
[Link]("Name is not present in the list");
}}}// end of derived class
57 | I S C C o m p u t e r S c i e n c e P r o j e c t
57
VDT
VARIABLE DATA TYPE DESCRIPTION
name[] String Store name
dob[] String Store date of birth
doj[] String Store date of joining
i String Looping
j String Looping
Temp String Temporary storage
n String Input name to be searched
INPUT:
Enter name in the cell 1:
Sunil Gupta
Enter date of birth in the cell 1:
12/09/1962
Enter data of joining in the cell 1:
23/09/1990
Enter name in the cell 2:
Ashok Mittal Enter date of birth in the cell 2:
22/08/1964
Enter data of joining in the cell 12/02/1991
Enter name in the cell 3:
Santosh Mishra
Enter date of birth in the cell 3:
18/05/1964
Enter data of joining in the cell 3:
16/06/1987
Enter name in the cell 4
Yogesh Kishore
Enter date of birth in the cell 4:
11/04/1960
58 | I S C C o m p u t e r S c i e n c e P r o j e c t
58
Enter data of joining in the
15/08/1994
Enter name in the cell 5:
Deepak Sen
Enter date of birth in the cell 5:
21/03/1970
Enter data of joining in the cell 5:
24/11/2001
OUTPUT:
The names with date of birth and date of joining are:
59 | I S C C o m p u t e r S c i e n c e P r o j e c t
59
BIBLIOGRAPHY
BOOKS:
1. Sumita Arora- A Textbook of Computer
Science with Java for Class 12
2. Understanding I.S.C. Computer Science
(Java with Blue J) Class- XII
INTERNET WEBSITES:
1. geeksforgeeks
2. [Link]
3. codecademy
4. Udemy
60 | I S C C o m p u t e r S c i e n c e P r o j e c t
60
61 | I S C C o m p u t e r S c i e n c e P r o j e c t
61