Experiment 2 (A) Aim: Theory:: To Calculate Average Marks of Student Using Classes and Objects in Java
Experiment 2 (A) Aim: Theory:: To Calculate Average Marks of Student Using Classes and Objects in Java
AIM: To calculate average marks of student using Classes and Objects in Java.
THEORY:
Java provides a data structure, the array, which stores a fixed-size sequential collection
of elements of the same type.
SOURCE CODE:
import java.util.Scanner; class Grade {
avg = avg / n;
} else if (avg >= 80 && avg < 90) { grade = "Very Good";
a[i] = sc.nextInt();
Output:
AIM: To implement Stack and Queue using Classes and Objects in Java.
THEORY:
A stack is an ordered list in which all insertions and deletions are made at one end, called the top. A
queue is an ordered list in which all insertions take place at one end, the rear, while all deletions take
place at the other end, the front. The restrictions on a stack imply that if the elements are added to
the stack, n that order, then the first element to be popped must the last element to be inserted into
the stack. For this reason stacks are sometimes referred to as Last In First Out (LIFO) lists. The
restrictions on queue imply that the first element which is inserted into the queue will be the first one
to be removed. Thus queues are known as First In First Out (FIFO)
SOURCE CODE:
// Stack
a[++top] = x;
void pop() {
void display() {
System.out.print("\n");
}
s.push(10);
s.push(20);
s.push(30);
s.push(40);
s.push(50);
s.push(60);
System.out.println("Stack After
Pushing:"); s.display();
s.pop();
s.pop();
Output:
Stack After Pushing: 10 20 30 40 50 60 60
is Popped
//Queue
void pop() {
void display() {
System.out.print("\n");
q1.push(20);
q1.push(30);
q1.push(40);
q1.push(50);
q1.push(60);
System.out.println("Queue After
Pushing:"); q1.display();
q1.pop();
System.out.println("Queue After
Popping:"); q1.display();
}
}
Output:
Queue After Pushing: 10 20 30 40 50 60
Queue After Popping: 20 30 40 50 60