logo

Crowdly

Dado el siguiente código: import tads.IStack; import tads.BoundedStack; publi...

✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.

Dado el siguiente código:

import tads.IStack;

import tads.BoundedStack;

public class Nav {

private String abierta;

private IStack<String> prevs;

private IStack<String> posts;

public Nav() {

prevs = new BoundedStack<String>();

posts = new BoundedStack<String>();

abierta = "en blanco";

}

public void openWeb(String url) {

prevs.push(abierta);

abierta = url;

}

public void retroceder() {

String anterior = abierta;

try {

abierta = prevs.peek();

prevs.pop();

posts.push(anterior);

}

catch (Exception e) {

System.out.print("No hay prevs->");

}

}

public void avanzar() {

String anterior = abierta;

try {

abierta = posts.peek();

posts.pop();

prevs.push(anterior);

}

catch (Exception e) {

System.out.print("No hay posts->");

}

}

public String toString() {

return abierta + "->";

}

public static void main (String[] args) {

Nav nav = new Nav();

System.out.print(nav);

nav.openWeb("a.es");

System.out.print(nav);

nav.openWeb("b.es");

System.out.print(nav);

nav.retroceder();

System.out.print(nav);

nav.avanzar();

System.out.print(nav);

nav.avanzar();

System.out.print(nav);

}

}

Escribe la salida en consola al ejecutarlo:

More questions like this

Want instant access to all verified answers on moodle.upm.es?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!