Advertisement
Merry123

Untitled

Dec 19th, 2022
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.30 KB | None | 0 0
  1. package Lab;
  2.  
  3. import java.util.ArrayDeque;
  4. import java.util.Scanner;
  5.  
  6. public class BrowserHistoryUpgrade {
  7.     public static void main(String[] args) {
  8.         Scanner sc = new Scanner(System.in);
  9.  
  10.         String command = sc.nextLine();
  11.  
  12.         String currentURL = "Blank";
  13.         ArrayDeque<String> historyStack = new ArrayDeque<>();
  14.         ArrayDeque<String> forwardQueue = new ArrayDeque<>();
  15.  
  16.  
  17.         while (!command.equals("Home")) {
  18.  
  19.             if (command.equals("back")) {
  20.                 if (!historyStack.isEmpty()) {
  21.                     currentURL = historyStack.pop();
  22.  
  23.                 } else {
  24.                     System.out.println("no previous URLs");
  25.                     command = sc.nextLine();
  26.                     continue;
  27.                 }
  28.             } else if (command.equals("forward")) {
  29.                 if (!forwardQueue.isEmpty()) {
  30.                     //TODO: ??
  31.                 } else {
  32.                     System.out.println("no next URLs");
  33.                 }
  34.  
  35.             } else {
  36.                 if (!currentURL.equals("Blank")) {
  37.                     historyStack.push(currentURL);
  38.                 }
  39.                 currentURL = command;
  40.             }
  41.             System.out.println(currentURL);
  42.             command = sc.nextLine();
  43.         }
  44.     }
  45. }
  46.  
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement