Computer Project Profile
Computer Project Profile
TERESA’s
COLLEGE
by:-AKARSH
SRIVASTAVA
1
class-12th
science
INDEX
2
Acknowledgement
In the accomplishment of this project successfully, many people have
given me their blessings and the heart pledged support, this time I
am utilising to thank all the people who have been concerned with
this project.
Primarily, I would thank god for being able to complete this project
with success. Then I would like to thank my principal Mrs.Geetika
Kapoor and computer teacher Mr.Luqman Khan whose valuable
guidance has been the ones that helped me patch this project and
make it full proof success. His suggestions and his instructions has
served as the major contributor towards the completion of the
project.
Then I would like to thank my and friends for their strong and
continuous support. Their valuable suggestions and guidance has
been helpful in various phases of the completion of the project.
Last but not the least I would like to thank my classmates who have
helped me a lot.
-AKARSH SRIVASTAVA
3
Introduction to java
Java is a general purpose object oriented language. It was developed
in 1991 in the U.S.A. by Sun Microsystems.
JAVA FEATURES-
JAVA ENVIROMENT-
BLUEJ-
4
Double
dimensional
array Programs
5
Ques.01-WAP to input numbers in 4*4 matrix and display the
original matrix. Transpose the original matrix and display it.
import java.util.*; //Package included for Scanner class
int i,j;
for(j=0;j<4;j++)
arr[i][j]=sc.nextInt();
for(i=0;i<4;i++)
for(j=0;j<4;j++)
System.out.print(arr[i][j]+"\t");
System.out.println();
6
}
for(j=0;j<4;j++)
System.out.print(arr[j][i]+"\t");
System.out.println();
} //End of class
Output :-
10
11
12 7
13
14
15
16
Original matrix :-
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Transpose matrix :-
1 5 9 13
2 6 10 14
3 7 11 15
4 8 12 16
int i,j;
for(j=0;j<4;j++)
arr[i][j]=sc.nextInt();
for(i=0;i<4;i++)
for(j=0;j<4;j++)
System.out.print(arr[i][j]+"\t");
System.out.println(); 9
}
for(j=0;j<4;j++)
if(i==0||j==0||i==3||j==3)
System.out.print(arr[i][j]+"\t");
else
System.out.print(" "+"\t");
System.out.println();
} //End of class
Output :-
8 10
9
10
11
12
13
14
15
16
Original matrix :-
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Boundary Elements matrix :-
1 2 3 4
5 8
9 12
13 14 15 16
11
Ques.03-WAP to input numbers in 4*4 matrix and display the
elements above the right diagonal.
import java.util.*; //Package included for Scanner class
int i=0,j=0;
for(j=0;j<=3;j++)
arr[i][j]=sc.nextInt();
System.out.println("Original Matrix");
for(i=0;i<=3;i++)
for(j=0;j<=3;j++)
System.out.print(arr[i][j]+"\t");
System.out.println();
} 12
System.out.println("Elements above right diagonal are");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
if((i+j)<3)
System.out.print(arr[i][j]+"\t");
System.out.println();
} //End of class
Output :-
10
11
12 13
13
14
15
16
Original Matrix
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Elements above right diagonal are
1 2 3
5 6
9
int i,j,k,temp=0;
for(j=0;j<4;j++)
arr[i][j]=sc.nextInt();
System.out.println("Original Matrix");
for(i=0;i<4;i++)
for(j=0;j<4;j++)
System.out.print(arr[i][j]+"\t");
System.out.println();
}
15
for(k=0;k<4;k++)
{
for(i=0;i<3;i++)
for(j=0;j<3-i;j++)
if(arr[k][j]>arr[k][j+1])
temp=arr[k][j];
arr[k][j]=arr[k][j+1];
arr[k][j+1]=temp;
System.out.println("Sorted Matrix");
for(i=0;i<4;i++)
for(j=0;j<4;j++)
System.out.print(arr[i][j]+"\t");
System.out.println();
} //End of class
Output :- 16
Enter the numbers in 4*4 matrix
4
3
12
11
10
16
15
14
13
Original Matrix
4 3 2 1
8 7 6 5
12 11 10 9
16 15 14 13
Sorted Matrix
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Test your program for the following data and some random
data:
Sample data:
Input n=4
Matrix ARR[ ][ ]=
2 5 6 9
8 4 1 3
2
6 7 3 1
1 2 2 1
2 4 1
Output:
Matrix ARR[ ][ ]=
2 5 6 9
8 4 1 3
2
6 7 3 1
1 2 2 1
2 4 1
No Saddle Point
19
import java.util.*; //Package included for Scanner class
class Saddle //Start of class
int n=sc.nextInt();
int min=0,max=0,flag=0;
int i=0,j=0,k=0,r=0,c=0;
for(j=0;j<n;j++)
arr[i][j]=sc.nextInt();
System.out.println("Original Matrix");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
System.out.print(arr[i][j]+"\t");
}
20
System.out.println();
}
for(i=0;i<n;i++)
min=arr[i][0];
c=0;r=0;
for(j=0;j<n;j++)
if(arr[i][j]<min)
min=arr[i][j];
c=j;
max=arr[0][c];
for(k=0;k<n;k++)
if(arr[k][c]>max)
max=arr[k][c];
r=k;
if(min==max)
{ flag=1;
break;
} 21
else
{
min=0;
max=0;
if(flag==1)
else
} //End of class
Output :-
10
11
22
12
13
14
15
16
Original Matrix
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
23
Ques.06-WAP to enter natural numbers in a double
dimensional array m*n (where m is the number of rows and n
is the number of columns). Display the greatest element of
the matrix. Display the new matrix.
Sample Input:
5 8 2 3
7 4 6 2
8 1 3 7
9 2 6 5
Sample Output:
9 8 2 9
7 9 9 2
8 9 9 7
9 2 6 9
int m=sc.nextInt();
int n=sc.nextInt();
int i=0,j=0;
form
for(i=0;i<m;i++) 24
//loop to input numbers in matrix
for(j=0;j<n;j++)
{
arr[i][j]=sc.nextInt();
System.out.println("Original Matrix");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
System.out.print(arr[i][j]+"\t");
System.out.println();
int max=arr[0][0];
for(i=0;i<m;i++)
for(j=0;j<n;j++)
if(arr[i][j]>max)
max=arr[i][j];
for(i=0;i<m;i++)
for(j=0;j<n;j++) 25
{
if((i==j)||(i+j)==3)
arr[i][j]=max;
System.out.println("Modified Matrix");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
System.out.print(arr[i][j]+"\t");
System.out.println();
} //End of class
Output :-
4 26
6
2
8
Original Matrix
5 8 2 3
7 4 6 2
8 1 3 7
9 2 6 5
Greatest element of the matrix is 9
Modified Matrix
9 8 2 9
7 9 9 2
8 9 9 7
9 2 6 9
27
Ques.07-WAP to store the numbers in n*m matrix in Double
Dimensional Array. Find the sum of the elements in each row
and each column. Display the sum of each row and each
column corresponding to the rows and columns.
Sample Input:
1 1 1 1
0 5 6 8
1 1 1 1
5 4 2 1
1 1 1 1
1 2 6 7
1 1 1 1
2 0 4 6
Sample Output:
1 1 1 1 5
0 5 6 8 9
1 1 1 1 5
5 4 2 1 2
1 1 1 1 5
1 2 6 7 6
1 1 1 1 5
2 0 4 6 2
4 5 5 6
8 1 8 2
int n=sc.nextInt();
int m=sc.nextInt();
28
int arr[][]=new int[n+1][m+1]; //Array declaration
int i=0,j=0,s=0;
System.out.println("Enter numbers in the "+n+"*"+m+" matrix");
for(j=0;j<m;j++)
arr[i][j]=sc.nextInt();
System.out.println("Original Matrix");
for(i=0;i<n;i++)
for(j=0;j<m;j++)
System.out.print(arr[i][j]+"\t");
System.out.println();
for(i=0;i<n;i++)
s=0;
for(j=0;j<m;j++)
s=s+arr[i][j];
arr[i][m]=s;
29
}
for(j=0;j<m;j++)
s=0;
for(i=0;i<n;i++)
s=s+arr[i][j];
arr[n][j]=s;
System.out.println("Modified Matrix");
for(i=0;i<n+1;i++)
for(j=0;j<m+1;j++)
System.out.print(arr[i][j]+"\t");
System.out.println();
} //End of class
Output :-
15
16
18
15
14
12
11
11
12
16
17
12
10
14
16
Original Matrix
10 15 16 18
15 14 12 11
11 12 16 17
12 10 14 16
Modified Matrix
10 15 16 18 59
15 14 12 11 52
11 12 16 17 56
12 10 14 16 52
48 51 58 62 0
String Programs
32
Ques.08-WAP to accept a string in a mixed case and display
the same in reversed order using ‘String Tokenizer’.
System.out.println("Enter a sentence");
String str=sc.nextLine();
String rev="";int i;
int c=str1.countTokens();
for(i=1;i<=c;i++)
String w=str1.nextToken();
rev=w+" "+rev;
System.out.println(rev);
} //End of class
33
Output :-
Enter a sentence
This is a cat
cat a is This
34
Ques.09-WAP to accept a sentence and convert ‘a’ to ‘an’
present in the string. The alphabet ‘a’ must not be the part of
word present in the string.
import java.util.*; //Package included for Scanner class
System.out.println("Enter a sentence");
String str=sc.nextLine();
String str1="";int i;
for(i=0;i<l-2;i++)
char ch=str.charAt(i);
char ch1=str.charAt(i+1);
char ch2=str.charAt(i+2);
str1=str1+ch1+"n";
else
str1=str1+ch1;
Output :-
Enter a sentence
36
Ques.10-WAP to accept two words in lower case and frame a
new word by taking one by one character from each word.
Assuming that the length of both the words is same.
import java.util.*; //Package included for Scanner class
int i,l;
char ch1,ch2;
String str1,str2,str3="";
str1=sc.nextLine();
str2=sc.nextLine();
for(i=0;i<l;i++)
ch1=str1.charAt(i);
str3=str3+ch1;
ch2=str2.charAt(i);
str3=str3+ch2;
System.out.println(str3); 37
} //End of void main
} //End of class
Output :-
dizzy
world
dwiozrzlyd
38
Ques.11-WAP to accept a String from the user and display the
frequency of word ‘the’ in the String.
int i,l,f=0;
char ch;
String str1,str2="";
System.out.println("Enter a String");
str1=sc.nextLine();
str1=str1+" ";
for(i=0;i<l;i++)
ch=str1.charAt(i);
if(ch!=' ')
str2=str2+ch;
else
if(str2.equalsIgnoreCase("the"))
f=f+1;
str2="";
39
}
}
System.out.println("Total frequency of 'the' in the string is-"+f);
} //End of class
Output :-
Enter a String
40
Ques.12-A simple encryption system uses a shifting process
to hide a message.The value of the shift can be in the range
of 1 to 26(otherwise,error ‘Invalid Shift Value’ should
appear).
Text: A BC D E F G H I J K L M N O P Q R S T U V W X Y Z
Code; U V W X Y Z A B C D E F G H I J K L M N O P Q R S T
Shift : 7
Shift : 29
41
import java.util.*; //Package included for Scanner class
String str=sc.nextLine();
System.out.println("Enter Shift");
int a=sc.nextInt();
int i=0,n=0,b=0;
str=str.toUpperCase();
String str1="";
if(a>26)
else
for(i=0;i<l;i++)
char ch=str.charAt(i);
b=(int)ch;
42
n=b+(a-1);
if(n>90)
n=n-26;
char ch1=(char)n;
str1=str1+ch1;
str1=str1.replace("QQ"," ");
System.out.println("Decoded Text");
System.out.println(str1);
} //End of class
Output :-
UHINBYLKKQCHHYLKK
Enter Shift
Decoded Text
ANOTHER WINNER
Ch char
43
Stores character of the String
String str=sc.nextLine();
str=str.toUpperCase();
int i=0,j=0,c=0,m=0;
char ch1,ch2;
for(i=65;i<=90;i++)
{ ch1=(char)i;
c=0;
44
for(j=0;j<l;j++)
{
ch2=str.charAt(j);
if(ch1==ch2)
c++;
if(c>m)
m=c;
x=ch1;
if("AEIOU".indexOf(x)>-1)
else
} //End of class
Output :-
45
VARIABLE DESCRIPTION TABLE
46
Ques.14-While typing, a typist has made two or more
consequtive blank spaces in a sentence. Write a program in
Java to replace two or more consequtive blanks by a single
blank.
String str=sc.nextLine();
str=str+" ";
int i=0;
char ch1,ch2;
String str1="";
int c=0,v=0; 47
for(i=0;i<(l-1);i++)
{
ch1=str.charAt(i);
ch2=str.charAt(i+1);
if("aeiouAEIOU".indexOf(ch1)>-1)
v++;
c++;
continue;
else
str1=str1+ch1;
System.out.println(str1);
System.out.println(v);
System.out.println(c);
} //End of class
Output :-
8
Total number of consonants are:
10
49
PATTERN &
SERIES
PROGRAMS
50
Ques.15- Write a programme to print the following
pattern
54321
4321
321
21
1
21
321
4321
54321
class pattern
{
public static void main(String args[])
{
int a,b,c,i,j,k,p=0,q=2,w=4;
System.out.println(“the pattern”);
for(i=5;i>=1;i--)
{
for(j=0;j<=p;j++)
{
System.out.print(k);
}
System.out.println();
}
p=p+1;
}
for(a=1;a<=4;a++)
{
51
for(b=w;b>=1;b--)
{
System.out.print(“ “);
}
for(c=q;c>=1;c--)
system.out.print(c);
}
System.out.println();
Q=+1;
W=w=+1;
}
}
}
Output :-
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1
2 1
3 2
4 3 2
1
1
52
5 4 3 2 1
Ques.16- WAP to generate the following pattern-
* * * * *
* *
* *
* *
* * * * *
class Pattern2 //Start of class
int i=0,j=0;
System.out.print("*"+" ");
System.out.println();
for(j=1;j<=5;j++)
if(j==1||j==5)
System.out.print("*"+" ");
if(j>1&&j<5)
53
System.out.print(" "+" ");
}
System.out.println();
System.out.print("*"+" ");
} //end of class
Output :-
* * * * *
* *
* *
* *
* * * * *
54
Ques.17- WAP to generate the following pattern-
0
12
345
6789
543
21
0
class Pattern3 //Start of class
int i=0,j=0,p=0;
for(j=1;j<=i;j++
System.out.print(p+" ");
p++;
System.out.println();
p=5;
55
for(i=3;i>=1;i--) //loop to print lower half
{
for(j=i;j>=1;j--)
System.out.print(p+" ");
p--;
System.out.println();
} //end of class
Output :-
12
345
6789
543
21
56
VARIABLE DESCRIPTION TABLE
Variable Data Type Description
57
Ques.18- WAP to print the sum of the following series-
x x2 x3
s= + + … … … … … .. nterms
1 2 3
int n=sc.nextInt();
int x=sc.nextInt();
double s=0,i,num=1;
s=s+Math.pow(x,num)/i;
num++;
} //End of Class
58
Output :-
Enter the value of n
3
59
Ques.19- WAP to print the sum of the following series-
x x x x
s= − + − … … … … … .. n terms
1 2 3 4
int n=sc.nextInt();
int x=sc.nextInt();
double s=0.0,sign=1.0,i;
s=s+sign*(x/i);
sign=-sign;
} //End of Class
60
Output :-
Enter the value of n
2
61
Ques.20- WAP to print the sum of the following series-
1 2 3 4
s=1+ + + + … … … … … … n terms
1! 2! 3! 4!
int n=sc.nextInt();
f=1;
f=f*j;
s=s+i/f;
}
62
//End of Void Main
//End of Class
Output :-
Enter the value of n
5
63
Number
programs
64
Ques.21-WAP to print all the Armstrong numbers between
100 and 1000.
int i=0,t=0,s=0,r=0;
r=t%10;
s=s+r*r*r;
t=t/10;
} //End of while
Loop
if(s==i)
System.out.print(i+", ");
} 65
//End of for Loop
} //End of Void
Main
} //End of Class
Output :-
66
Ques.22-WAP to input a binary number and convert it into its
decimal Equivalent.
n = sc.nextInt();
int t=n;
r =t%10;
d = d + r*i;
i = i*2;
t = t/10;
System.out.println(d);
} 67
//End of void main
} //End of class
Output:-
1100
12
68
Ques.23-WAP to input two numbers and print the HCF and
LCM of the two numbers.
x = scan.nextInt();
y = scan.nextInt();
a = x;
b = y;
t = b;
b = a%b;
a = t;
hcf = a;
lcm = (x*y)/hcf;
} //End of class
Output:-
10
HCF = 2
LCM = 30
70
Ques.24-WAP to input a number and check whether it is a
Unique number or not.
int n=sc.nextInt();
int t;
t=n; c=0;
r=t%10;
if(i==r)
c++;
t=t/10;
if(c>1)
{ 71
flag=0;
break;
}
if(flag==1)
else
} //End of class
Output:-
4215
It is an Unique Number
72
Ques.25-WAP to input a decimal number and convert it into
its Binary Equivalent.
import java.util.*; //Package included for Scanner
class
long n=sc.nextInt();
long c=1,r=0,rev=0;
long t=n;
r=t%2;
rev=rev+r*c;
c=c*10;
t=t/2;
System.out.println(rev);
73
} //End of void main
} //End of class
Output:-
12
1100
74
Ques.26-WAP to input elements in an array and sort them by
using insertion sort.
public class InsertionSort //Start of class
int n = array.length;
int i = j-1;
i--;
array[i+1] = key;
for(int i:arr1)
}
System.out.print(i+" ");
75
System.out.println();
insertionSort(arr1); //sorting array using insertion sort
for(int i:arr1)
System.out.print(i+" ");
} //End of class
Output:-
76
Function
programs
77
Ques.27-Write a program to accept two numbers and check
whether they are twin prime or not. The function returns 1, if
it is twin prime otherwise, returns 0.
int i,c=0,f=0;
if(n%i==0)
c=c+1;
if(c==2)
f=1;
return(f);
int m,p,x,y;
m=sc.nextInt();
System.out.println("Enter your second number");
p=sc.nextInt();
x=ob.prime(m);
y=ob.prime(p);
if((x==1&&y==1)&&(m-p==2||p-m==2))
else
} //End of class
Output :-
11
13
int
C int Used to breaking the number into
two parts
int A variable for returning 1 or 0
N int Formal parameter to store the
entered number
M int Used to store First number
P int Used to store Second number
X int 79
Used to store the returned value
from function
Y int Used to store the returned value
from function
Ques.28-WAP to enter a number and check whether it is a
kapraker number or not, using function.
int t, c=1;
t=n;
c=c*10;
t=t/10;
int sq=n*n;
int r=sq%c;
int p=sq/c;
int z=p+r;
80
if(z==n)
return 1;
else
return 0;
int a=sc.nextInt();
int x=ob.kap(a);
if(x==1)
else
} //End of class
81
Output :-
45
It is a Kapraker number
82
Ques.29-WAP to enter a number and check whether it is an
Evil number or not, using function. It returns 1 if the number
of 1’s is even else returns 0.
long t=n;
r=t%2;
rev=rev+r*c;
c=c*10;
t=t/2;
System.out.println(rev);
t=rev;
83
while(t>0) //while loop for counting no. of 1 in binary
equivalent
r=t%10;
if(r==1)
p++;
t=t/10;
if(p%2==0)
return 1;
else
return 0;
long a=sc.nextInt();
long z=ob.Enumber(a);
if(z==1)
else
}
} //End of void main
//End of class
84
Output :-
12
1100
It is an Evil Number
85
Ques.30-WAP to enter a number and check whether it is an
Automorphic number or not, using function. It returns 1 if the
number is automorphic else returns 0.
c++;
t=t/10;
int sq=n*n;
int z=(int)Math.pow(10,c);
int k=sq%z;
if(k==n)
return 1;
else
return 0;
int a=sc.nextInt();
int x=ob.morphic(a);
if(x==1)
else
} //End of class
Output :-
25
It is an Automorphic number
T int
from function
87
Temporary variable to store the
value of n
Ques.31- A class Merger concatenates two positive integers
that are greater than 0 ad produces a new merged integer.
Example- If the first number is 23 and the second is 764, then
the concatenated number will be 23764.
Member functions:
Specify the class Merger, giving the details of the constructor, void
readNum(), void JoinNum(), void show(). Define the main() function to
create an object and call the functions accordingly.
long n1,n2,mergNum;
88
Merger() //Constructor
{
n1=0;
n2=0;
mergNum=0;
n1=sc.nextInt();
n2=sc.nextInt();
String s=Long.toString(n1);
String s1=Long.toString(n2);
String s2=s+s1;
mergNum=Long.valueOf(s2);
{
89
//Start of void main
ob.readNum();
ob.JoinNum();
ob.show();
} //End of class
Output :-
23
746
First Number= 23
90
Ques.32- A class ConsChange has been defined with the
following details:
Class name : ConsChange
Member functions:
String word;
int len;
ConsChange() //Constructor
{
91
len=0;
word="";
}
void readword() //to accept word in lowercase
word=sc.next();
len=word.length();
String s="";
char c;
for(int i=0;i<len;i++)
c=word.charAt(i);
if(c!='a'&&c!='e'&&c!='i'&&c!='o'&&c!='u')
s+=c;
for(int i=0;i<len;i++)
c=word.charAt(i);
if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
s+=c;
word=s;
} 92
void changeword() //to change the case of shifted
words
{
char c;String s="";
for(int i=0;i<len;i++)
c=word.charAt(i);
if(c!='a'&&c!='e'&&c!='i'&&c!='o'&&c!='u')
s+=(char)(c-32);
else
s+=c;
shiftcons();
changeword();
ob.readword();
ob.show();
} //End of class
93
Output :-
Enter word in Lower case
welcome
94
inheritence
programs
95
Ques.33- Write a class Sentence to store a sentence and
another class Duplicate to replace the duplicate characters.
The details of the classes are given below:
Member functions:
Member functions:
Specify the class Sentence, giving the details of the constructor, void
Accept(), void Display(). Define the main() function to create an
object and call the functions accordingly 96
Using the concept of inheritance, specify the class Duplicate giving
the details of the functions void Remove(), also initialise both the
constructors in the sub-class.
Sample Input: Ammmiitt Kuuulkkkarnni iiissss aa nicccceee
bbbooy
Sentence() //Constructor
str="";
void Accept()
str=sc.nextLine();
void Display()
System.out.println("Original Sentence");
System.out.println(str);
int p;
97
Duplicate()
super();
p=0;
void Remove()
{ String str1="";
str=str+" ";
p=str.length();
for(int i=0;i<p-1;i++)
char ch1=str.charAt(i);
char ch2=str.charAt(i+1);
if(ch1==ch2)
continue;
else
str1=str1+ch1;
Display();
System.out.println("Modified Sentence");
System.out.println(str1);
ob.Accept();
ob.Remove();
}
} //End of void main
//End of class
98
Output :-
Original Sentence
Modified Sentence
99
Ques.34- A super class Bank has been defined to store the
details of a customer. Define a sub-class Account thet enables
transactions for the customer with the bank. The details of
the both the classes are given below:
Member functions:
Member functions:
}
void display()
{
System.out.println("The name is "+name);
System.out.println("The account number is "+accno);
System.out.println("The Principal amount is "+p);
}
}
import java.util.*;
class Account extends Bank
{
double amt;
Account(String n1, long a1, double p2)
{
super(n1,a1,p2);
}
amt=0.0;
101
void deposit()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the amount to deposit");
amt=sc.nextDouble();
p=p+amt;
}
void withdraw()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the amount to withdraw");
amt=sc.nextDouble();
if(amt>p)
System.out.println("INSUFFICIENT BALANCE");
else
{
p=p-amt;
if(p<500)
p=p-(500-p)/10;
}
}
void display()
{
super.display();
System.out.println("The new amount is "+ p);
}
public static void main(String args[]) //Start of void
main
{
Account ob=new Account("Raam Singh",111254587,5000.0);
ob.deposit();
ob.withdraw();
ob.display();
} //End of void main
} //End of class
102
Output :-
103
Stack
Programs
104
Ques.35- Register is an entity which can hold maximum 100
names. The register enables the user to add and remove
names from the top most end only.
Member functions:
Specify the class Register giving the details of the functions void
push (String) and String pop( ). Assume that the other functions have
been defined
The main function need NOT be written.
105
import java.util.*; //Package included for Scanner class
int cap;
int top;
cap=max;
top=-1;
if(top==cap-1)
System.out.println("OVERFLOW");
else
top++;
stud[top]=n;
}
106
String pop() //To remove names from the top location
{
if(top==-1)
return "$$";
else
String n=stud[top];
top--;
return n;
void display()
for(int i=0;i<=top;i++)
System.out.println(stud[i]);
} //End of class
107
queue
programs
108
Ques.36- Queue is an entity which can hold maximum 100
integers. The queue enables the user to add integers from
the rear and remove integers from the front.
Member functions:
Specify the class Queue giving the details of the functions void
addele(int) and int delete( ). Assume that the other functions have
been defined
The main function need NOT be written.
int size;
int front;
int rear;
size=mm;
front=0;
rear=0;
{ 110
if(rear==size-1)
System.out.println("OVERFLOW");
else
if(front==0&&rear==0)
front=1;
rear=1;
else
rear++;
Que[rear]=v;
if(front==0&&rear==0)
System.out.println("Underflow");
return -9999;
else
int v=Que[front];
if(front==rear)
front=0;
rear=0; 111
}
else
front++;
return v;
void display()
for(int i=front;i<=rear;i++)
System.out.println(Que[i]);
} //End of class