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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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);
}
}
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply