1. Develop a Java package with simple Stack and
Queue classes. Use JavaDoc comments for documentation
ALGORITHM:
step 1:Define package pack1 with
the keyword package.
step 2:Define the class ArrayQueue
with the integers.
step 3:Using a 1 argument
constructor,the max size of the queue is assigned.
step 4:Define the method insert()
with an item in object type as argument to insert an item.
step 5:Define the method remove()
to delete an item from the queue.
step 6:Define the method peek() to
return the item which is at the top of stack.
Step 7:Define the method
displayAll() to display the contents of the queue.
step 8:Terminate the class .Create
an another package pack1 using the keyword package.
step 9:Define the class ArrayStack
with an object array'a' and an integer top as datamembers.
step 10:Using a one argument
constructor define the size of the array.
step 11:Define the method push() to
push an item into the stack.
step 12:Define the method pop() to
delete an item from the stack.
step 13:Define the method peek() to
return the item at the top of the stack.
step 14:Terminate the class.
step 15:Import the package
pack1,define the class StackQueueDemo.
step 16:Define the main() in the
class.
Create objects for the classes
ArrayStack and ArrayQueue and access the methods using the objects.
step 17:Display the result.
step 18: terminte the main() and
terminate the class.
2. Design a Date class similar to the one
provided in the java.util package
ALGORITHM
step
1:Define the class MyDate with members date,month,year,hour,min,sec.
step
2:USing a default constructor,set the values using the predefined Dateclass.
step
3:use parameterised constructors to set the values for the members.
step
4:Define the methods getYear(),getMonth(),getDate(), to return the year,month,date .
step
5:Define the methods setYear(),setMonth(),setDate. to set the values for
year,month,date,.
step
6:Define the method after() with the return type boolean to check whether the
given date is after the current date.
step
7:Define the method before() with the return type boolean to check whether the
given date is before the current date.
step
8:Define the method compareTo() with the return type integer to compare two
dates.it will return 0 if both are same,will return 1 if date is after currrent
date else it returns -1.
step
9:terminate the class.
step
10:Define the datetest and define the main() in it.
step
11:Create many objects for the class MyDate and access the methods of the class
using different objects.
step
12:Display the result.
step
13:terminate the main() and class.
No comments:
Post a Comment