Professional Documents
Culture Documents
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