Definition
This is a bonus classwork and is worth +4 points on a single Homework grade (for a complete, working, on-time submission)!
For example, if you got a 97/100 on HW1, you’ll get 101/100 instead!
Careful
In order to get your solutions back in a timely fashion, this classwork has an abbreviated due-date — check the course page for more info!
You are designing your own web browser, because why the hell not? Everyone else seems to be doing it these days, and you’ll be damned if ForneyFox isn’t off the ground before Chrome totally takes over!
So, you decided to start at the basics:
Definition
Design a web browser navigation suite that can be used to (1) visit sites, (2) return users to previously visited sites, and (3) move forward to previously visited sites that were returned from (just like how you (1) visit sites on a browser and can (2) hit the back button or (3) hit the forward button).
GitHub Classroom + Skeleton
Definition
Start with the solution skeleton in-hand! The following will also serve as your submission mechanism (see submission instructions below).
Assignment
Specifications
For now, during development, we’ll just be developing the methods for a WebNavigator class.
Here are the viable commands:
-
visit(site): navigates to the specified URL and is flagged as the “currently viewing.”Remark
This would be like typing in some URL into your browser’s navigation bar and then hitting enter.
-
back(): navigates to most recent site on which the abovevisitcommand was invoked.Remark
This would be like hitting the back button on your browser.
-
forw(): navigates to the most recent site from which the abovebackcommand was used. The “forward” collection is wiped after visiting a new site through thevisitcommand (see examples below).Remark
This would be like hitting the forward button on your browser.
These commands are then processed in the main method of your WebNavigator class.
Definition
Your task: complete the WebNavigator class outlined below to achieve the above specified behavior. An example useage is found below:
// Example Interaction
WebNavigatorSolution navi = new WebNavigatorSolution();
navi.visit("www.google.com");
System.out.println(navi.getCurrent());
// www.google.com
navi.visit("www.reddit.com");
System.out.println(navi.getCurrent());
// www.reddit.com
navi.back();
System.out.println(navi.getCurrent());
// www.google.com
navi.back();
System.out.println(navi.getCurrent());
// www.google.com
navi.forw();
System.out.println(navi.getCurrent());
// www.reddit.com
navi.forw();
System.out.println(navi.getCurrent());
// www.reddit.com
navi.visit("www.facebook.com");
System.out.println(navi.getCurrent());
// www.facebook.com
navi.back();
System.out.println(navi.getCurrent());
// www.reddit.com
// Visiting another site after moving back wipes
// the "forward" collection
navi.visit("www.amazon.com");
System.out.println(navi.getCurrent());
// www.amazon.com
// See? doesn't go back to reddit
navi.forw();
System.out.println(navi.getCurrent());
// www.amazon.comYour application should have the above behavior and you should verify its functionality with extra tests as well!
Toolkit
You may use any of the classes we’ve covered in the Java Collections framework for this assignment! Don’t get used to the freedom, you can’t use it on your homework yet.
Your options are:
- ArrayLists
- LinkedLists
- Stacks
- Queues
Here are some added details:
- Before visiting a site, the current site can be considered
null; users should not be able to usebackcommands to return to null. - Moving back at the first visited site or forward at the last visited site keeps the current site where it is.
- If you’re clever with your data structure choice, you only need to write ~13 - 15 lines of code to complete this assignment.
- Big Hint: Don’t feel limited to a single data structure, OR a single copy of a single data structure.
Remark
Need more hints on how your WebNavigator is meant to behave? Just head to your own web browser!
Submission
Definition
You will be submitting your assignments through GitHub Classroom!
What
Complete all classes that accomplishes the specification above, in the project structure given in the skeleton above.
How
To clone this assignment (if you need a refresher), consult the guide here:
Assignment
To submit this assignment:
- Simply push your final, submission copy to the GitHub Classroom repository associated with you or your group.
- If you worked in a group (3 individuals maximum), ensure that your GitHub Classroom group includes all members, and place all group members’ names at the top of all submitted files (in appropriate
JavaDoc commenting fashion) AND in the accompanying
readmefile.