Java 268
Java 268
Java 268
queueSize = 0;
frontIndex = 0;}
public ArrayQueue() {
this(1000);}
return queueSize;}
if (queueSize == data.length)
data[avail] = e;
queueSize++;}
1|Page
public E first() throws IllegalStateException {
if (queueSize == data.length)
return data[frontIndex];}
if (queueSize == data.length)
E answer = data[frontIndex];
data[frontIndex] = null;
queueSize--;
return answer;}
queue.enqueue(18);
queue.enqueue(79);
queue.enqueue(90);
2|Page
Output-
public ArrayStack() {
this(CAPACITY);}
topIndex = -1;
if (size() == data.length)
data[++topIndex] = e;}
3|Page
if (empty())
return data[topIndex];}
if (empty())
E answer = data[topIndex];
data[topIndex] = null;
topIndex--;
return answer;}
mystack.push(9);
mystack.push(3);
mystack.push(8);
mystack.push(10);
4|Page
Output-
5|Page
Program-02
Program-Design a class for Complex numbers in java.In addition to
methods for basic operations on complex numbers,provide a method to
return the number of active objects created.
Code-
class Complex {
Complex() {}
real = tempReal;
imaginary = tempImaginary;}
return temp;}
return temp;}
void printComplexNumber() {
public classGFG {
6|Page
public static void main(String[] args) {
C1.printComplexNumber();
C2.printComplexNumber();
C3 = C3.addComp(C1, C2);
System.out.print("Sum of ");
C3.printComplexNumber();
C3 = C3.subtractComp(C1, C2);
System.out.print("Difference of ");
C3.printComplexNumber();}
Output-
7|Page
Program-03
Program-Develop with suitable hierarchy, class for point, shape
rectangle, square, circle, ellipse, triangle,polygenetic.
Code-
class point {
void display() {
void display() {
void display() {
System.out.println("This is rectangle.");}
double area = l * b;
void display() {
System.out.println("This is square.");}
double area = s * s;
8|Page
void display() {
System.out.println("This is circle.");}
void display() {
System.out.println("This is ellipse.");}
void display() {
System.out.println("This is triangle.");}
double area = (b * h) / 2;
class findArea {
p.display();
9|Page
s.display();
r.display();
r.printArea(2, 6);
sq.display();
sq.printArea(5, 1);
c.display();
c.printArea(4, 1);
e.display();
e.printArea(5, 3);
t.display();
t.printArea(9, 1);}
}Output-
10 | P a g e
Program-04
Program-Design a Simple test application to demonstrate dynamic
polymorphism.
Code-
class TestElement {
test1.displayTest();
test2.displayTest(); }}
Output-
11 | P a g e
12 | P a g e