Project Programe 1 To 15
Project Programe 1 To 15
A class that has been defined to keep the books from bottom to top one by
one till the space is available. The details of the class Rack are given below:
Member functions/methods:
voidkeepBook(): to input the name of a book in bkNam and keep it in the rack
at the current point index if space is available, otherwise display the message
rack is full.
voidtakeBook():to remove a book from the rack and print if rack is not empty
Void printBooks():display the book names present in the rack, if rack is empty
class Rack
Step 1: start
Step 1: start
Step 5: end
Step 1: start
Step 3: end
voidkeepBook ()
Step 1: start
Step 2: input name of the book in bkNam and keep in rack if space is available
otherwise display a
Step 3: end
voidtakeBook ()
Step 1: start
Step 4: end
voidprintBooks ()
Step 1: Start
Step:2Display the book names present in the rack,if rack is empty then print “rack s
empty”
Class Ended
import java.util.*;
class Rack
String bkNam;
inti, size,point;
Rack(int cc)
size=cc;
point =-1;
for(i=0;i<size;i++)
rack[i]="";
voidkeepBook()
bkNam=sc.nextLine();
if(point==(size-1))
System.out.println("Rack is full");
else
{
point++;
rack[point]=bkNam;
voidtakeBook()
String b;
if(point==-1)
System.out.println("Rack is empty")
else
b=rack[point];
System.out.println("Removed Book="+b);
point--;
voidprintBook()
if(point==-1)
System.out.println("Rack is empty");
}
else
System.out.println("Book Name:");
for(i=(point-1);i>=0;i--)
System.out.println(rack[i]);
int s=sc.nextInt();
ob.keepBook();
ob.keepBook();
ob.keepBook();
ob.takeBook();
ob.printBook();
}
OUTPUT:
computer
economics
language
Members functions/methods:
point (int mm, int nn): constructor to initialise mm to m and nn into n as actual
columns.
void print_saddle_point():to find and print the saddle point from the matrix
corresponding column
ALGORITHM:class point
Step 1: start
Step 1: start
Step 6: end
point ()
Step 1: start
Step 4: end
Step 1: start
Step 3: end
void get_mat ()
Step 1: start
Step 4: end
void display_matt ()
Step 1: start
Step 4: end
void print_saddle_point ()
Step 1: start
Step 2: local variables c, k, f=0,i,j, min, max are initialised and declared
Step 4: end
class ended
import java.util.*;
class point
int m,n;
point()
int i,j;
for(i=0;i<10;i++)
for(j=0;j<10;j++)
arr[i][j]=0;
m=mm;
n=nn;
void get_mat()
int i,j;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
ar[i][j]=sc.nextInt();
void display_matt()
int i,j;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
System.out.println();
void print_saddle_point()
int c,k,f=0,i,j,min,max;
for(i=0;i<m;i++)
{
min=arr[i][0];
c=0;
for(j=0;j<n;j++)
min=arr[i][j,c=j;
max=arr[k][c];
for(k=0;k<n;k++)
if(arr[k][c]>max)
if(max==min)
f=1;
if(f==0)
}
public static void main()
int mm,nn;
mm=sc.nextInt();
nn=sc.nextInt();
ob.get_mat();
ob.display_matt();
ob.print_saddle_point();
}
OUTPUT:
3574
1649
2475
3574
1649
2475
Class name:PrintJob
Members function/methods:
void addJob-adds the new printing job at the end point of the last printing job,
if possible otherwise
Void removeJob() :remove the printing job from the front of the printing job is
Specify the class print job given the details of the constructor and function.
Algorithm:-
Step 1: start
Step 6: end
PrintJob()
Step 1:start
Step 3: end
void addJob()
Step 1: start
Step 5: end
void removeJob()
Step 1:start
Step 2: condition to check whether front and rear is equals to -1, if yes
Step 7: end
void displayJob()
Step 1: start
Step 4: end
import java.util.*;
class PrintJob
PrintJob()
Capacity =20;
Front=-1;
Rear=-1;
void addJob()
Newjob-sc.nextInt();
if(Rear==(Capacity-1))
else
if(Front==-1&&Rear==-1)
Front =0;
Rear=0;
else
Rear=Rear+1;
job[Rear]=newJob;
void removeJob()
if(Front=-1&&Rear ==-1)
System.out.println("JOB IS EMPTY");
else
int val=job[Front];
if(Front==Rear)
else
Front=-1;
Rear=-1;
else
Front=Front+1;
void displayJob()
{
int i;
System.out.println("JOBS:");
for(i=Front;i<=Rear;i++)
System.out.println(job[i]);
ob.addJob();
ob.addJob();
ob.addJob();
ob.addJob();
ob.removeJob();
ob.displayJob();
}
OUTPUT:-
Enter new job
Jobs:
4
Variable Description Table:-
A super class record has been defined to store the names and ranks of 50 students.
Define a
subclass Rank to find the highest rank along with the name.
Members functions
Member functions/methods:
void highest():find the index/location of the topmost rank and store it in index without
void display (): display the names and ranks along with the name having the topmost
rank.
ALGORITHM:-
class record
Step 1: start
Step 2: a single dimension array name and rank of size 50 are initialised
Record ()
Step 1: start
Step 4: end
void readValues ()
Step 1: start
Step 2: accept the name and rank of the students from the user
Step 3: end
void display ()
Step 1: start
Step 2: print the name of the students and ranks with suitable headings
Step 3: end
class ended
Step 1: start
Rank ()
Step 1: start
Step 3: end
void highest ()
Step 1: start
Step 2: find the index of the topmost rank and store it in index without sorting
Step 3: end
void display ()
Step 1: start
Step 2: print the names and ranks of the students with the name having the topmost
rank
Step 3:
end
import java.util.*;
class Record
Record()
for(int i=0;i<50;i++)
name[i]="";
rnk[i]=0;
void readValues()
for(int i=0;i<50;i++)
name[i]=sc.next();
rnk[i]=sc.nextInt();
void display()
System.out.println("NAME\t\t"+"RANK");
for(int i=0;i<50;i++)
System.out.println(name[i]+"\t\t"+rnk[i]);
int index;
Rank()
index=0;
void highest()
for(int i=0;i<50;i++)
if(rnk[i]<rnk[index])
index=i;
void display()
super.display();
}
OUTPUT:-
ENTER NAME OF THE STUDENT:
SUMAN
11
AMAN
ASHOK
NITIN
MOHIT
NAME
SUMAN
AMAN
ASHOK
NITIN
MOHIT
RANK
11
4
7
2
9
THE TOPMOST RANK: 2
A disarium number is a number in which the sum of digit to the power of their respective
position is
design a class Disarium to check if a given number is a disarium number or not some of the
members
data members:
Members methods
Disarium (int nn): parameterized constructor to initialise the data members n=nn end and
size=0
void countDigit(): count the total number of digit and assign it to size
int sumofDigit(int n, int p): return the sum of the digits of the number (n)to the power of their
void check(): check whether the number is a disarium number and display result with an
appropriate
message.
specific the class Disarium giving the details of the constructor(), void countDigit (), white
count digits in
sum of digit(int,int),void check(). define the main function to create an object and call the
function of
class disarium
Step 1: start
Step 5: end
Step 1: start
Step 2: initialise the data members n=nn and size=0
Step 3: end
void countDigit ()
Step 1: start
Step 4: end
Step 1: start
Step 2: local variables i, d and sum of int type are initialised and declared
Step 3: return the sum of the digits of the number (n) to the power of their respective position (p) using
recursive technique
Step 4: end
void check ()
Step 1: start
Step 2: method sum of digits is called
Step 3: if the sum of digit to the power of their respective position is equal to the number itself, print
"Disarium Number" else print " Not a Disarium Number"
"
Step 4: end
class ended
import java.util.*;
class Disarium
{
int num, size;
Disarium(int nn)
{
num=nn, size=0;
}
void countdigit()
{
int p=num;
while(p>0)
{
p=p/10, size++;
}
}
int sumofdigits(int n,int p)
{
int d,sum=0;
for(int i=(p-1);i>=0;i--)
{
d=n/(int)(Math.pow(10,i));
sum sum+(int)(Math.pow(d,(p-i)));
n=n%(int)(Math.pow(10,i));
}
return sum;
}
void check()
{
if(sumofdigits(num,size)==num)
System.out.println("Disarium Number");
else
System.out.println("Not a Disarium Number");
}
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a Number");
int no-sc.nextInt();
Disarium ob=new Disarium (no);
ob.countdigit();
ob.check();
}
}
OUTPUT:-
Enter a number
135
Disarium number
Enter a number
122
A class name SwapSort has been define to perform string related operation on a word input
some of the
Member functions/methods:
void swapchar():to interchange the first and last character of the word in 'wrd' and store the
new word
in swapwrd.
void display (): display the original words swapped word and the sorted word
Specify the class SwapSort given the details of the constructor (),void readword (),void
swapchar(), void
display(). Define the main () function to create an object and class the functions accordingly
to enable
the task.
ALGORITHM:-
class SwapSort
Step 1: start
Step 2: instance variables wrd, swapwrd, sortwrd of String and len of int type are initialised
public SwapSort ()
Step 1: start
Step 3: end
void readword ()
Step 1: start
Step 4: end
void swapchar ()
Step 1: start
Step 3: swap the first and last characters of the word in 'wrd' and store the new word in '
'swapwrd'
Step 4: end
void sortword ()
Step 1: start
Step 3: sort the characters of the original word in alphabetical order and store it in 'sortwrd'
import java.util.*;
class SwapSort
String wrd,swapwrd,sortwrd;
int len;
public SwapSort()
wrd="";
len=0;
swapwrd="";
sortwrd="";
void readword()
wrd=sc.next();
len=wrd.length();
void swapchar()
char ch1,ch2;
ch1=wrd.charAt(0);
ch2=wrd.charAt(len-1);
swapwrd=ch2+wrd.substring(1,len-1)+ch1;
void sortword()
{
int i,j;
for(i=65;i<=90;i++)
for(j=0;j<len;j++)
if(wrd.charAt(j)==i)
sortwrd=sortwrd+wrd.charAt(j);
void display()
System.out.println("Original word\t"+wrd);
System.out.println("Swapped word\t"+swapwrd);
System.out.println("Sorted word\t"+sortwrd);
ob.readword();
ob.swapchar();
ob.sortword();
ob.display();
}
OUTPUT :-
Enter a word in upper case
COMPUTER
A class mixer has been define to merge two sorted integer arrays in ascending order. some
of the
Member functions:
void accept():to accept the element of the array in ascending order without any duplicates.
Mixer mix(Mixer A):tomorrow is the current objects are element with the parameterized array
element
specify the class mixer, given details of the constructor void accept(), Mixermix (Mixer) and
void
display(), define the main () function to create an object and call the function accordingly to
enable the
task.
ALGORITHM:-
Step 1: Start
Step 4: End
Step 1: Start
Step 3: end
void accept ()
Step 1: Start
Step 3: End
Mixer mix(Mixer A)
Step 1: Start
Step 3: merging the current object's array elements with the parameterized array elements
and
Step 4: end
void display ()
Step 1: start
Step 4: end
import java.util.*;
class Mixer
int arr[];
int n;
Mixer(int nn)
n=nn;
arr=new int[n];
void accept()
for(int i=0;i<n;i++)
arr[i]=sc.nextInt();
Mixer mix(Mixer A)
for(int i=0;i<A.n;i++)
t.arr[i]=A.arr[i];
for(int j=0;j<n;j++)
t.arr[A.n+j]=arr[j];
return(t);
void display()
{
System.out.println("Merged elements:");
for(int i=0;i<n;i++)
System.out.println(arr[i]);
ob1.accept();
ob2.accept();
ob3=ob2.mix(ob1);
ob3.display();
}
OUTPUT:-
Enter elements of both the arrays one by one is ascending order:
43
54
65
76
87
98
99
Merged elements:
43
54
65
76
87
98
99
Variable Description Table:-
Design a class called change to convert a decimal number into its equivalent number in base
16 and vice
versa
Member functions/methods:
Specify the class change given the details of the constructor and functions void input (), void
hexadeci
(String str) and void decihexa (). The main function need not to be written.
ALGORITHM:-
Class: Change
Step 1: start
Change ()
Step 1: start
Step 3: end
void input ()
Step 1: start
Step 3: end
Step 1: start
Step 5: end
void hexadeci ()
Step 1: start
class ended
import java.util.*;
class Change
{
int a[]=new int[50];
int n,i;
Change()
{
for(i=0;i<50;i++)
{
a[i]=0;
n=0;
}
}
void input()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a decimal number");
n=sc.nextInt();
}
void decihexa(String str)//to convert hexadecimal number back to decimal form
{
int a=0,len,p=0,k=0;
double d=0,s=0;
String str1="";
char ch;
len=str.length();
p=len;
for(i=0;i<len;i++)
{
ch=str.charAt(i);
if(ch>='A')
k=(int)ch-55;
else
{
str1=str1+ch;
k=Integer.parseInt(str1);
str1="";
}
d=Math.pow(16,(p-1))*k;
s=s+d;
p--;
}
System.out.print("The decimal equivalent of Hexadecimal Number"+str+"is:");
System.out.print((int)s);
}
void hexadeci()//to convert decimal integer to hexadecimal form
{
int i=0,c=0,r,t;
String str2="";
System.out.print("The Hexadecimal equivalent of Decimal Number"+n+"is:");
while(n>0)
{
r=n%16;
a[i]=r;
n=n/16;
i++;
c++;
}
for(i=(c-1);i>=0;i--)
{
if(a[i]>=10)
{
t=a[i]-10;
t=65+t;
str2=str2+(char)t;
}
else
{
str2=str2+(char) (48+a[i]);
}
System.out.print(str2);
System.out.println();
decihexa(str2);
}
}
Output:-
Description
Enter a decimal number
35
The Hexadecimal equivalent of Decimal Number35 is: 23
The decimal equivalent of Hexadecimal Number23 is: 35
Enter a decimal number
107
The Hexadecimal equivalent of Decimal Number 107 is: 6B
The decimal equivalent of Hexadecimal Number 6B is: 107
Variable Description Table:-
Variable Data Type Description
A class "ISC_Scores" define the scores of a candidate in 6 subject and another class
Class name:ISC_Scores
Data members
int number [6][2]: to contain marks for 6 subject and subject code.
Member function/methods:
int point(int): to return the point in each subject according to the following conditions.
Marks>=90: 1 point
80-90. 2 point
70-79. 3 point
60-69. 4 point
50-59.5 point
40-49. 6. point
: accordingly
Members functions/methods
void bestsubjects():display the total points and best four subject codes using the concept of
inheritance
specify the details of both the classes using the concept of inheritance. specify details of the
constructor
iscscores(),methods int point(int) and void bestsubject(). Assume that other methods are
written for
void getiscscores ()
Step 1: start
Step 3: subject codes and marks in 6 different subjects are taken input
Step 4: end
Step 1: start
Step 2: local variable i and p of int type are initialised and declared
Step 4: end
class ended
void bestsubject()
Step 1: start
Step 2: display the total points and best four subject codes
Step 3: end
class ended
import java.util.*;
class ISC_Scores
{
protected int number[][]=new int[6][2];
void getiscscores()
{
Scanner sc=new Scanner(System.in);
int i;
System.out.println("Enter subject codes and marks in 6 different subjects:");
for(i=0;i<6;i++)
{
number[i][0]=sc.nextInt();
number[i][1]=sc.nextInt();
}
}
int point(int sub_score)
{
int i,pt=0;
for(i=1;i<=6;i++)
{
if(sub_score>=(100-i*10))
{
pt=i;
break;
}
}
return(pt);
}
} //end of base class
class Bestfour extends ISC_Scores
{
int i,j,k,t=0,temp,c=2;
void bestsubject()
{
for(i=0;i<6;i++)
t=t+point(number[i][1]);
System.out.println("Total points obtained:");
System.out.println(t);
for(i=0;i<6-1;i++)
{
for(j=0;j<(6-1-i);j++)
{
if(number[j][1]<number[j+1][1])
{
for(k=0;k<c;k++)
{
temp-number[j][k];
number[j][k]=number[j+1][k];
number[j+1][k]=temp;
}
}
}
}
System.out.println("Subject code with 4 best scores:");
for(i=0;i<4;i++)
System.out.println(number[i][0]+"\t\t"+number[i][1]);
}
} //end of derived class
OUTPUT:-
Enter subject codes and marks in 6 different subjects:
00
88
12
87
14
90
15
94
16
91
18
85
Total points obtained:
9
Subjects codes with best scores:
15 94
16 91
14 90
11 88
Variable Description Table:-
Void display ()
Step 1: start
Step 2: super class is called
Step 3: local variable total of double type is initialised to store the total amount to pay
Step 4: print the no. of days, fine and total amount to be paid
Class endedz
import java.util.*;
class Library
{
String name;
String author;
double p;
Library(String nm,String au,double pr)
{
name=nm;
author=au;
p=pr;
}
void show()
{
System.out.println("Title"+"\t"+author+"\t"+"Price in Rs.");
System.out.println(name+"\t"+author+"\t"+p);
}
} //end of base class
class Compute extends Library
{
int d;
double f;
Compute(String n,String a,double prc,int dy)
{
super(n,a,prc);
d=dy;
f=0.0D;
}
void fine()
{
if(d>7)
{
if((d-7)<=5)
f=2*(d-7);
elseif((d-7)>5&&(d-7)<=10)
f=3*(d-7);
else
f=5*(d-7);
}
}
void display()
{
super.display();
double total;
System.out.println(“No of days taken to return the book:\t”+d);
System.out.println(“Fine charged:\t”+f);
total=(2.0/100.0*p)+f;
System.out.println(“Total amount to be paid :\t”+total):
}
}//end of derived class
OUTPUT:-
Title PANDEY & DEY Price in Rs.
Members functions/methods:
void print_mat_and_sum(): to print the matrix of mxn and also print sum of greatest element
from each
row.
void change_diagonal(): enter the size of x. Change the value of both the diagonals of matrix
ar[][] by x,
if m=n and print the new matrix,otherwise print the message "it is not a square Matrix so
change is not
possible".
ALGORITHM:-
class matrix_operation
public static void main (String args[])
Step 1: start
Step 2: object of the class is created
Step 3: methods are called
Step 4: end
void getrowcolumn ()
Step 1: start
Step 2: accept the value of rows and columns
Step 3: end
void getmatrix ()
Step 1: start
Step 2: A local variable i and j of int type is initialised
Step 3: elements for the array are taken input
Step 4: end
void print_mat_and_sum ()
Step 1: start
Step 2: a local variables i, j, p=0, s=0 are initialised and declared
Step 3: the array is displayed
Step 4: print the sum of greatest element from each row
Step 5: end
void change_diagonal ()
Step 1: start
Step 2: a local variable i and j of int type are initialised
Step 3: accept the value of x
Step 4: if m = n print the new matrix otherwise print the message "it is not a square Matrix,so
change is
is not possible"
Step 5: end
import java.util.*;
class matrix_operation
{
int ar[][]=new int[10][10];
int m,n,x;
void getrowcolumn()
{
Scanner sc =new Scanner(System.in);
System.out.println("ENTER THE VALUES OF m AND n");
m=sc.nextInt();
n=sc.nextInt();
}
void getmatrix()
{
Scanner sc=new Scanner(System.in);
int i,j;
System.out.println("ENTER NUMBERS");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
ar[i][j]=sc.nextInt();
}
}
}
void print_mat_and_sum()
{
int i,j,s=0,p=0;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
System.out.print(ar[i][j]+"");
}
System.out.println();
}
for(i=0;i<m;i++)
{
p=0;
for(j=0;j<n;j++)
{
if(ar[i][j]>p)
{
p=ar[i][j];
}
}
s=s+p;
}
System.out.println("SUM OF GREATEST ELEMENT OF EACH ROW="+s);
}
void change_diagonal()
{
Scanner sc =new Scanner (System.in);
int i,j;
System.out.println("ENTER THE VALUE OF x");
x=sc.nextInt();
if(m==n)
{
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if((i==j)||((i+j)==2))
{
ar[i][j]=x;
System.out.print(ar[i][j]+"");
}
}
System.out.println();
}
}
else
{
System.out.println("IT IS NOT A SQUARE MATRIX SO CHANGE IS NOT POSSIBLE");
}
}
public static void main()
{
matrix_operation ob=new matrix_operation();
ob.getrowcolumn();
ob.getmatrix();
ob.print_mat_and_sum();
ob.change_diagonal();
}
}
OUTPUT:-
ENTER THE VALUES OF m AND n
4
4
ENTER NUMBERS
6
4
3
6
2
7
4
6
3
76
3
5
4
6
4
3
6436
2746
37635
4643
SUM OF GREATEST ELEMENT OF EACH ROW=95
ENTER THE VALUE OF x
9
99
9
99
9
Variable Description Table:-
Members functions/methods:
void sort():to sort arr[] in ascending order to using insertion sort method.
int binasearch(int start,int last): to search and return index of num from the ascending order
are if (num)
void printresult():by invoking function in binasearch () print the index and the element to be
searched
Design a class exchange to accept a sentence and interchange the first alphabet with the
last alphabet
for each word in the sentence with single letter word remaining unchanged. The words in the
input
sentence are separated by a single blank space and terminated by a full stop.
For example
Some of the data remember members and members functions are given below.
members function:
exchange():default constructor.
void exfirstlast(): each words and interchange the first and the last alphabet of the word form
a new
void display(): display the originals sentence along with the new change sentence.
Specify the class exchange() given details of the constructor with void read sentence and
void display
It is a warm day.
Original sentence : it is a warm day.
New sentence : ti si a marw yad.
Variable Description Table:-
A class Matrix contain a two-dimensional integer array of order m into n value possible for
both m and n
is 25. design a class Matrix to find the difference of the two Matrix the details of the members
of the
Member function
Rearrange (int mm,int nn):constructor to initialise the size of the matrix m=mm and n=nn
Rearrange SubMat(Matrix A):subtract the current object from the matrix of the parameter is
object and
specify the class Matrix given the details of the constructor (int, int), void fillarray (),
Rearrange
SubMat(Matrix) and void display(). define a main function to create an object and call the
function
A class prime series defines a recursion function to find the prime number from a list of data.
The details
Member functions/methods:
void Accept(): to accept the limit and input the integer in array arr[] up to the limit.
int IsPrime(int num,int j,int f) :to check n is prime or not, using Recursive Technique .If prime
then the
void Displayprime(): to display prime numbers from the array[] by invoking in IsPrime up to
Specific the class prime series given the details of the constructor white except in his prime
Step 5: end
prime_series()
Step 1: start
Step 3: end
void accept ()
Step 1: start
Step 4: end
int IsPrime(int,int)
Step 1:start
Step 2: through a recursive technique check whether the input number is prime or not
Step 4: end
void Displayprime ()
Step 1:start
Step 2: display the prime number from the array by invoking IsPrime
Step 4: end
import java.util.*;
class Prime_Series
{
Scanner sc=new Scanner(System.in);
int limit;
int arr[]=new int[150];
Prime_Series()
{
limit=0;
int i;
for(i=0;i<150;i++)
{
arr[i]=0;
}
}
void Accept()
{
int j;
System.out.println("ENTER THE NUMBER OF ELEMENTS TO STORE:");
limit=sc.nextInt();
System.out.println("ENTER THE ELEMENTS:");
for(j=0;j<limit;j++)
{
arr[j]=sc.nextInt();
}
}
int Isprime(int num,int j,int f)
{
if(j==num)
return (f);
else
{
if(num%j==0)
f=0;
return(Isprime(num,++j,f));
}
}
void PrintPrime()
{
int v;
for(int i=0;i<limit;i++)
{
v=Isprime(arr[i],2,1);
if(v==1)
System.out.println(“NUMBER”+arr[i]+”IS PRIME”):
}
}
OUTPUT:-
ENTER THE NUMBER OF ELEMENTS TO STORE:
7
ENTER THE ELEMENTS:
11
21
37
43
57
87
47
NUMBER 11 IS PRIME
NUMBER 37 IS PRIME
NUMBER 43 IS PRIME
NUMBER 47 IS PRIME
Variable Description Table:-