Can someone help me to correct the error of this code so that it is able to run at Jeliot tool?

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Can someone help me to correct the error of this code so that it is able to run at Jeliot tool? 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);

}

}

}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY