Page 1 of 1

I need help. I am not able to run this code in jeliot tool. Can someone run this code and screenshot 1) how this code lo

Posted: Sat Feb 19, 2022 3:20 pm
by answerhappygod
I need help. I am not able to run this code in jeliot tool.
Can someone run this code and screenshot 1) how
this code looks on the jeliot tool theatre and 2) call
tree. Then attach the answer here? I need the 2 screenshots.
Thanks.
package com.company;
import jeliot.io.Output;
import java.util.ArrayList;
public class Main {
static MyStack stack = new
MyStack();
public static void main(String[] args) {
beginLine();
firstInspect();
secondInspect();
thirdInspect();
}
static void beginLine() {
System.out.println("Beginning vehicle line...");
System.out.println("Pushing
numer 2 to stack");
System.out.println("Pushing
numer 1 to stack");
System.out.println("Pushing
numer 0 to stack");
stack.push(2);
stack.push(1);
stack.push(0);
}
static void firstInspect() {
int item
= stack.pop();
System.out.print("First
inspection, popping first item: " + item);
System.out.println();
}
static void secondInspect() {
int item
= stack.pop();
System.out.print("Second
inspection, popping second item: " + item);
System.out.println();
}
static void thirdInspect() {
int item
= stack.pop();
System.out.print("Third
inspection, popping third item: " + item);
System.out.println();
}
static class MyStack {
ArrayList<Integer> list = new
ArrayList<>();
void clear() {
this.list.clear();
}
int length() {
return
this.list.size();
}
void push(int num) {
if (this.list.size()
>= 3) {
Output.println("Stack is full!");
return;
}
this.list.add(num);
}
int pop() {
if (this.list.size()
<= 0) {
Output.println("Stack is empty!");
return
0;
}
int length =
this.list.size();
int target =
this.list.get(length - 1);
this.list.remove(length - 1);
return target;
}
int topValue() {
if (this.list.size()
<= 0) {
Output.println("Stack is empty!");
return
0;
}
return
this.list.get(this.list.size() - 1);
}
}
}