SHARE
TWEET

Untitled

a guest Jun 3rd, 2019 103 in 96 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package Lab;
  2.  
  3. import java.util.ArrayDeque;
  4. import java.util.ArrayList;
  5. import java.util.Scanner;
  6.  
  7. public class BrowserHistoryUpgrade{
  8.     public static void main(String[] args) {
  9.         Scanner scanner = new Scanner(System.in);
  10.  
  11.         // stacks is LIFO => Last in First Out
  12.         // queue is FIFO => First in First out
  13.  
  14.  
  15.         String input = scanner.nextLine();
  16.  
  17.         ArrayDeque<String> url = new ArrayDeque<>();
  18.         ArrayDeque<String>forwardPaged = new ArrayDeque<>();
  19.  
  20.         while (!input.equalsIgnoreCase("home")) {
  21.  
  22.  
  23.             if (!input.equalsIgnoreCase("back") && !input.equalsIgnoreCase("forward")) {
  24.                 url.push(input);
  25.                 System.out.println(url.peek());
  26.             } else if (input.equalsIgnoreCase("back") && url.size()<=1) {
  27.                 System.out.println("no previous URLs");
  28.             } else if (input.equals("forward") && forwardPaged.size()<1) {
  29.                 System.out.println("no next URLs");
  30.  
  31.             } else if (input.equalsIgnoreCase("back")) {
  32.                 forwardPaged.addFirst(url.pop());
  33.                 System.out.println(url.peek());
  34.  
  35.             }else if (input.equals("forward")){
  36.                 url.push(forwardPaged.peek());
  37.                 System.out.println(forwardPaged.peek());
  38.                 forwardPaged.clear();
  39.  
  40.             }
  41.  
  42.             input = scanner.nextLine();
  43.         }
  44.     }
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top