Browser History You're reading this text in a web browser, a program installed on your computer...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Browser History You're reading this text in a web browser, a program installed on your computer that allows you to visit URLs (sometimes called "links" or "web pages"). Let's implement the back and forward buttons in a web browser. Write a Browser History class using only stacks; no queues, lists, etc. Constructor BrowserHistory (String url) constructs a new Browser History object with the given url. Methods void visit(String url) visits the given url, clearing any forward history. String back() moves the history back 1 page and returns the current URL. String forward() moves the history forward 1 page and returns the current URL. String current() returns the current page URL. List pages () returns all back and forward URLs in the order they were visited. public class Browser { public static void main(String[] args) { Browser History history = new Browser History ("uw.edu"); // You are on "uw.edu". Visit "my.uw.edu"... history.visit("my.uw.edu"); // You are on "my.uw.edu". Visit "cs.uw.edu"... } } history.visit("cs.uw.edu"); // You are on "cs.uw.edu". Visit "canvas.uw.edu"... } history.visit("canvas.uw.edu"); printStatus (history); // You are on "canvas.uw.edu". Move back to "cs.uw.edu"... history.back(); // You are on "cs.uw.edu". Move back to "my.uw.edu"... history.back(); // You are on "my.uw.edu". Move forward to "cs.uw.edu"... history.forward(); // You are on "cs.uw.edu". Visit "notify.uw.edu", clearing the forward history... history.visit("notify.uw.edu"); // You are on "notify.uw.edu". We just cleared the forward history, so moving forward has no effect. history.forward(); printStatus (history); // You are on "notify.uw.edu". Move back 2 steps to "cs.uw.edu" then to "my.uw.edu"... for (int i = 0; i < 2; i += 1) { history.back(); } printStatus (history); // You are on "my.uw.edu". Attempt to move back 7 steps, but there's only "uw.edu" in the history... for (int i = 0; i < 7; i += 1) { history.back(); } printStatus (history); public static void printStatus (Browser History history) { System.out.println("Current page: " + history.current()); System.out.println("Full history: " + history.pages()); System.out.println(); H ~ m tin 67 1 import java.util.*; 2 3 public class Browser History { 4 5 // post: constructs a new BrowserHistory object with the given url public Browser History (String url) { } 8 a 9 10 11 12 A A A 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32} // post: visits the given url, clearing any forward history public void visit(String url) { } // post: moves the history back 1 page and returns the current url public String back() { return null; } // post: moves the history forward 1 page and returns the current url public String forward() { return null; } // post: returns the current page url public String current() { return null; } // post: returns all back and forward urls in the order they were visited public List pages() { return null; } Browser History You're reading this text in a web browser, a program installed on your computer that allows you to visit URLs (sometimes called "links" or "web pages"). Let's implement the back and forward buttons in a web browser. Write a Browser History class using only stacks; no queues, lists, etc. Constructor BrowserHistory (String url) constructs a new Browser History object with the given url. Methods void visit(String url) visits the given url, clearing any forward history. String back() moves the history back 1 page and returns the current URL. String forward() moves the history forward 1 page and returns the current URL. String current() returns the current page URL. List pages () returns all back and forward URLs in the order they were visited. public class Browser { public static void main(String[] args) { Browser History history = new Browser History ("uw.edu"); // You are on "uw.edu". Visit "my.uw.edu"... history.visit("my.uw.edu"); // You are on "my.uw.edu". Visit "cs.uw.edu"... } } history.visit("cs.uw.edu"); // You are on "cs.uw.edu". Visit "canvas.uw.edu"... } history.visit("canvas.uw.edu"); printStatus (history); // You are on "canvas.uw.edu". Move back to "cs.uw.edu"... history.back(); // You are on "cs.uw.edu". Move back to "my.uw.edu"... history.back(); // You are on "my.uw.edu". Move forward to "cs.uw.edu"... history.forward(); // You are on "cs.uw.edu". Visit "notify.uw.edu", clearing the forward history... history.visit("notify.uw.edu"); // You are on "notify.uw.edu". We just cleared the forward history, so moving forward has no effect. history.forward(); printStatus (history); // You are on "notify.uw.edu". Move back 2 steps to "cs.uw.edu" then to "my.uw.edu"... for (int i = 0; i < 2; i += 1) { history.back(); } printStatus (history); // You are on "my.uw.edu". Attempt to move back 7 steps, but there's only "uw.edu" in the history... for (int i = 0; i < 7; i += 1) { history.back(); } printStatus (history); public static void printStatus (Browser History history) { System.out.println("Current page: " + history.current()); System.out.println("Full history: " + history.pages()); System.out.println(); H ~ m tin 67 1 import java.util.*; 2 3 public class Browser History { 4 5 // post: constructs a new BrowserHistory object with the given url public Browser History (String url) { } 8 a 9 10 11 12 A A A 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32} // post: visits the given url, clearing any forward history public void visit(String url) { } // post: moves the history back 1 page and returns the current url public String back() { return null; } // post: moves the history forward 1 page and returns the current url public String forward() { return null; } // post: returns the current page url public String current() { return null; } // post: returns all back and forward urls in the order they were visited public List pages() { return null; }
Expert Answer:
Related Book For
Financial Accounting Tools for Business Decision Making
ISBN: 978-1118644942
6th Canadian edition
Authors: Paul D. Kimmel, Jerry J. Weygandt, Donald E. Kieso, Barbara Trenholm, Wayne Irvine
Posted Date:
Students also viewed these programming questions
-
Case Study: Quick Fix Dental Practice Technology requirements Application must be built using Visual Studio 2019 or Visual Studio 2017, professional or enterprise. The community edition is not...
-
If we take $1 away from a rich person and give it to a poor person, the rich person loses less utility than the poor person gains. Comment.
-
During the most recent year, Michael Co. bought 3,800 shares of Canada common stock at $38, 640 shares of Brazil stock at $47.25, and 1,500 shares of Russian stock at $77 - all as available for sale...
-
ACME Global is a technology company that specializes in producing Accounting Software. Management is in the process of creating a new software called the 'No Limit' that identifies issues in...
-
Identify the two ways that trial material may be organized. What are the advantages and disadvantages of each method?
-
Selected accounts for Winslow Inc. as at December 31, 2014, are as follows: Instructions Prepare closing entries for Winslow Inc. on December 31, 2014. $ 5,000 22,000 Sales Returns and Allowances...
-
The risk-free rate is 4%. The optimal tangency (market) portfolio has an expected return of 18% and a standard deviation of 25%. You currently own a portfolio with an expected return of 10% and a...
-
Obtain the Laplace transform of f (t) in Fig. 15.28 . f(t) A 15 1 2 3 4 t
-
Upon viewing the Randy Pausch video provided in the Coursework area, summarize in your own words what you learned from this video and how you could use this at work for your employees. This...
-
For a microprocessor-based control system, 16Kbyte ROM and 4Kbyte RAM are needed. ROM and RAMs are required to be placed in the regions given below in the system memory map. 2764 IC will be used as...
-
Braden Brothers, Inc... is an architecture firm specializing in high-rise buildings. Its job-costing system has a single direct-cost category (architectural labor) and a single indirect-cost pool,...
-
(20 points) Consider a prismatic (unswept), thin-walled NACA 0015 airfoil (uncambered) of chord c. It is made of uniform sheet aluminum (thickness t) with no internal spars. T 0.15c N C + -y (a) Look...
-
Prepare the overhead budget for the first quarter of 2021 using the following data: The machine hours for January, February and March are 7000, 8000 and 6000 units respectively. The variable overhead...
-
13 34 Transform 2 4 10 into a unit matrix by using elementary transformations. 3 8
-
X p(x) X P(x) 1 0.1 1,1 1,2 1,3 1,4 1,5 2,1 2,2 2,3 2,4 2,5 3,1 3,2 3,3 Sample Mean 1.0 1.5 2.0 2.5 3.0 1.5 2.0 2.5 3.0 3.5 2.0 50 1.0 1.5 2.0 2.5 3 3.5 0.01 0.08 0.2 0.18 0.16 2.5 2 0.4 3.0 3 0.2...
-
You are a U.S. investor who purchased British securities for 2,000 one year ago when the British pound cost U.S. $1.50. What is your total return (based on U.S. dollars) if the value of the...
-
Ajax Limited reported the following information (in millions) at December 31, 2015: net sales $14,000; profit $550; total assets at December 31, 2015, $7,200; and total assets at December 31, 2014,...
-
These financial statement items are for Batra Corporation at year end, July 31, 2015: Batra started the year with $6,000 of common shares and issued additional shares for $4,000 during the year....
-
Condensed statement of financial position and income statement data for Colinas Corporation follow: Additional information: 1. The allowance for doubtful accounts was $2,400 in 2013, $2,750 in 2014,...
-
If the least-squares regression line has slope b1 = 5, and two x-values differ by 3, the predicted difference in the y-values is _____________________. In Exercises 57, fill in each blank with the...
-
For each of the following plots, interpret the y-intercept of the least-squares regression line if possible. If not possible, explain why not. a. The least-squares regression line is = 1.98 +...
-
Substituting the value of the explanatory variable for x in the equation of the least-squares regression line results in a prediction for y. In Exercises 812, determine whether the statement is true...
Study smarter with the SolutionInn App