Create an advance data type to represent web page history Na

Create an advance data type to represent web page history. Name this class \'WebHistory\'. The following should be the private members of this class: 1- int totalPagesVisited; 2- WebPagell pages; As you can see, you also need to class \"WebPage\" which should have the following private members: 1- Date visitedOn; 2- String url; 3- String content; Implement all the necessary. constructors and all the getters/setters for these classes. Now, inside main(), write a test code to test the working of your class. The test code should be something like this: public static void main(String[] args) {//this is just a sample, you must test every function you wrote. WebHistory myhist = new WebHistory(2);//totalPagesVisited should be 2 Date today = new Date(10, 10, 2016); Date yesterday = new Date(9, 10, 2016); WebPage pi = new WebPage(today, \"www.google.com\", \"This is Google\'s webpage\"); WebPage p2 = new WebPage(yesterday, \"www.yahoo.com\", \"This is Yahoo\'s webpage\"); myhis.t.Add(pl); myhist. Add(p2); System.out.printIn(myhist);

Solution

import java.util.Date;

public class WebPage {

   Date visitedOn;
   String url;
   String content;

   /**
   * @param visitedOn
   * @param url
   * @param content
   */
   public WebPage(Date visitedOn, String url, String content) {
       this.visitedOn = visitedOn;
       this.url = url;
       this.content = content;
   }

   /**
   * @return the visitedOn
   */
   public Date getVisitedOn() {
       return visitedOn;
   }

   /**
   * @param visitedOn
   * the visitedOn to set
   */
   public void setVisitedOn(Date visitedOn) {
       this.visitedOn = visitedOn;
   }

   /**
   * @return the url
   */
   public String getUrl() {
       return url;
   }

   /**
   * @param url
   * the url to set
   */
   public void setUrl(String url) {
       this.url = url;
   }

   /**
   * @return the content
   */
   public String getContent() {
       return content;
   }

   /**
   * @param content
   * the content to set
   */
   public void setContent(String content) {
       this.content = content;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return \"WebPage [visitedOn=\" + visitedOn + \", url=\" + url
               + \", content=\" + content + \"]\";
   }

}

import java.util.Arrays;

public class WebHistory {

   int totalPagesVisited;
   WebPage[] pages;

   /**
   * @param totalPagesVisited
   * @param pages
   */
   public WebHistory(int totalPages) {
       this.totalPagesVisited = 0;
       this.pages = new WebPage[totalPages];

   }

   public boolean Add(WebPage p) {

       if (totalPagesVisited < pages.length) {
           pages[totalPagesVisited] = p;
           totalPagesVisited++;
           return true;
       } else
           return false;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return \"WebHistory [totalPagesVisited=\" + totalPagesVisited
               + \", pages=\" + Arrays.toString(pages) + \"]\";
   }

}

import java.util.Date;

public class TestWebHistory {
   public static void main(String[] args) {

       WebHistory myhist = new WebHistory(2);
       Date today = new Date(10, 10, 2016);
       Date yesterday = new Date(9, 10, 2016);

       WebPage p1 = new WebPage(today, \"www.google.com\",
               \"This is Google\'s webpage\");
       WebPage p2 = new WebPage(yesterday, \"www.yahoo.com\",
               \"This is Yahoo\'s webpage\");

       myhist.Add(p1);
       myhist.Add(p2);

       System.out.println(myhist);

   }
}

OUTPUT:

WebHistory [totalPagesVisited=2, pages=[WebPage [visitedOn=Mon May 08 00:00:00 IST 1916, url=www.google.com, content=This is Google\'s webpage], WebPage [visitedOn=Sun May 09 00:00:00 IST 1915, url=www.yahoo.com, content=This is Yahoo\'s webpage]]]

 Create an advance data type to represent web page history. Name this class \'WebHistory\'. The following should be the private members of this class: 1- int to
 Create an advance data type to represent web page history. Name this class \'WebHistory\'. The following should be the private members of this class: 1- int to
 Create an advance data type to represent web page history. Name this class \'WebHistory\'. The following should be the private members of this class: 1- int to

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site