Announcement

Collapse
No announcement yet.

Requesting help on Java Programming

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Here you go but you have to realise that if you don't understand what is going on in the code I've sent then you are only cheating yourself :P

    Leave the HashMaps alone, yes they are awesome and really useful but you don't need them for this assement! (Although you could use them there is really no need).

    I have removed the code for altavista but I haven't removed the boxes for them in the display because its much easier for you to do in the form viewer (without the class.form file that doesn't show up in netbeans hence I'd have to do it manually and assed with that).

    You'll also need to add 2 boxes to display the queries resultant HTML code and pass a reference to it to the thread, just do it the same way I have for displaying the search queries, I've marked in the code where to put the instruction to set the text.

    I've used the <cite> and <a id="r search terms he went on about but it still sometimes returns the advertised links in the results rather than the true results. Rather than go about trying to get rid of them I'd just mention it in the report (assuming you have to write a report).

    Finally keep in mind that this isn't optimised, commercial level code, this is "doing-an-assessment-for-someone-on-a-forum-for-little-or-no-reward" level code so don't be surprised if there is any feedback on it being a bit sloppy, you get what you pay for basicly

    I'll store that 'I'll hack something for you offer' for future reference
    Attached Files

    Comment


    • #17
      Originally posted by RyanfaeScotland View Post
      Here you go but you have to realise that if you don't understand what is going on in the code I've sent then you are only cheating yourself :P

      Leave the HashMaps alone, yes they are awesome and really useful but you don't need them for this assement! (Although you could use them there is really no need).

      I have removed the code for altavista but I haven't removed the boxes for them in the display because its much easier for you to do in the form viewer (without the class.form file that doesn't show up in netbeans hence I'd have to do it manually and assed with that).

      You'll also need to add 2 boxes to display the queries resultant HTML code and pass a reference to it to the thread, just do it the same way I have for displaying the search queries, I've marked in the code where to put the instruction to set the text.


      used the <cite> and <a id="r search terms he went on about but it still sometimes returns the advertised links in the results rather than the true results. Rather than go about trying to get rid of them I'd just mention it in the report (assuming you have to write a report).

      Finally keep in mind that this isn't optimised, commercial level code, this is "doing-an-assessment-for-someone-on-a-forum-for-little-or-no-reward" level code so don't be surprised if there is any feedback on it being a bit sloppy, you get what you pay for basicly

      I'll store that 'I'll hack something for you offer' for future reference
      Thank you so much. I own you a big favour.
      Keep Smile + Let's be together !! + Magical Glasses + Cowabunga + Superhero + Maximum Carnage

      Comment


      • #18
        Originally posted by RyanfaeScotland View Post
        Here you go but you have to realise that if you don't understand what is going on in the code I've sent then you are only cheating yourself :P

        Leave the HashMaps alone, yes they are awesome and really useful but you don't need them for this assement! (Although you could use them there is really no need).

        I have removed the code for altavista but I haven't removed the boxes for them in the display because its much easier for you to do in the form viewer (without the class.form file that doesn't show up in netbeans hence I'd have to do it manually and assed with that).

        You'll also need to add 2 boxes to display the queries resultant HTML code and pass a reference to it to the thread, just do it the same way I have for displaying the search queries, I've marked in the code where to put the instruction to set the text.

        I've used the <cite> and <a id="r search terms he went on about but it still sometimes returns the advertised links in the results rather than the true results. Rather than go about trying to get rid of them I'd just mention it in the report (assuming you have to write a report).

        Finally keep in mind that this isn't optimised, commercial level code, this is "doing-an-assessment-for-someone-on-a-forum-for-little-or-no-reward" level code so don't be surprised if there is any feedback on it being a bit sloppy, you get what you pay for basicly

        I'll store that 'I'll hack something for you offer' for future reference


        Ok, I completed the assignment but there is something which is incomplete

        5) Your application will create an additional 2 separate threads to download and write out the contents of the webpage to a file. (each thread will do both downloading and writing of the file)


        The requirements is to write out the contents of the webpage to a file

        total text files to be write out is 10 textfiles.

        10 text files consists of 5 top bing results and 5 top ask.com results

        Bing top 5 results

        PageRead.readPage("gshi.org") ->1st bing text file
        PageRead.readPage("www.gshi.org/?s=v2") ->2nd bing text file
        PageRead.readPage("www.gshi.es") ->3rd bing text file
        PageRead.readPage("www.gshi-steel.com") ->4th bing text file
        PageRead.readPage("gshi.com") -> 5th bing text file

        Ask.com top 5 results

        PageRead.readPage("gshi.org") ->1st ask text file
        PageRead.readPage("www.gshi.org/?s=v2&sys=6 ") ->2nd ask text file
        PageRead.readPage("www.gshi.org/?s=v2 ") ->3rd ask text file
        PageRead.readPage("www.gshi.org/?s=v2&sys=5") ->4th ask text file
        PageRead.readPage("www.gshi.net/ ") ->5th ask text file


        How am I suppose to write out the 10 textfiles?
        Last edited by silentkiller; 08-09-2011, 05:43:51 AM.
        Keep Smile + Let's be together !! + Magical Glasses + Cowabunga + Superhero + Maximum Carnage

        Comment


        • #19
          Copy and paste the file-writing code another 5 times for each thread, Add a loop that goes round the file-writing code 5 time, create 5 search and write threads, that's the different ways that spring to mind but I'd go with adding a loop to the code, its the most sensible.

          Are you sure you need 10 copies of the file and its not 1 file with 10 lines (i.e. all the results in one file)?

          Comment


          • #20
            Originally posted by RyanfaeScotland View Post
            Copy and paste the file-writing code another 5 times for each thread, Add a loop that goes round the file-writing code 5 time, create 5 search and write threads, that's the different ways that spring to mind but I'd go with adding a loop to the code, its the most sensible.

            Are you sure you need 10 copies of the file and its not 1 file with 10 lines (i.e. all the results in one file)?
            Yes. 10 copies of text files.

            I want to ask about inside the content file-writing code, How am I suppose to retrieve specific element from queue just like retrieving element that I want from the array.

            What is the "?" code inside the PageRead.readPage (read and write the html content of 1st top seach results)
            PageRead.readPage("?") ->1st bing or ask text file

            What is the "?" code inside the PageRead.readPage (read and write the html content of 2nd top seach results)
            PageRead.readPage("?") ->2nd top bing or ask text file

            How to use just one filewriter to write out the content of each 5 top search results?

            Can you solve the PageRead.readPage("?") . I mean,

            I just want the example of the first file writer code of retrieving 1st element (1st Bing search result) and retrieving 6th element (1st Ask search result) from the queue.

            Read the 1st element(Bing 1st Result) and write out the content of 1st bing result into 1st textfile of bing
            tRead the 6th element (Ask.com 1st Result) and write out the content of 1st ask.com result into 1st textfile of ask.com

            so that The rest of 4 filewriter I can study the first file writer code example and do it myself.
            Last edited by silentkiller; 08-09-2011, 07:07:54 PM.
            Keep Smile + Let's be together !! + Magical Glasses + Cowabunga + Superhero + Maximum Carnage

            Comment


            • #21
              Originally posted by silentkiller View Post
              Yes. 10 copies of text files.

              I want to ask about inside the content file-writing code, How am I suppose to retrieve specific element from queue just like retrieving element that I want from the array.
              In a normal queue you can only get the elements from the front position. If you picture a queue at a bank then this is what happens, people enter at the back and leave through the front and when the person at the front leaves the rest of the people move up 1 position. So to get elements from the queue you have to use the queue.peek() or queue.poll() method, peek will get you the item without removing it and poll will get you the item and remove it hence moving the rest of the elements along the queue. You'll see in my code I made use of the (String s : queue) loop which basicly says for each String in queue do something.

              What is the "?" code inside the PageRead.readPage (read and write the html content of 1st top seach results)
              PageRead.readPage("?") ->1st bing or ask text file

              What is the "?" code inside the PageRead.readPage (read and write the html content of 2nd top seach results)
              PageRead.readPage("?") ->2nd top bing or ask text file
              I'm not sure what you mean by this, I can't see anywhere that calls readPage on "?" or are you using that to mark some variable? PageRead.readPage("http://www.bing.com") sents a http request to bing.com and returns a string builder with the results which will be the HTML code.

              If you are on about the line that has the matching comments i.e.
              // Write the HTML contents of 1st result of bing or ask
              try{
              BufferedWriter out = new BufferedWriter(new FileWriter(w1));
              String s="1";
              out.write(s);
              out.newLine();
              out.close();

              Then to get a line and put it out you just need to grab it from the queue:

              // Write the HTML contents of 1st result of bing or ask
              try{
              BufferedWriter out = new BufferedWriter(new FileWriter(w1));

              String s="1";
              s = s + " " + queue.poll();
              out.write(s);

              out.newLine();

              out.close();

              But you might want to make sure poll() returns something first.

              How to use just one filewriter to write out the content of each 5 top search results?
              So you are looking for 1 filewriter to write out 5 results to bing.txt and then 5 results to ask.txt yes? Then just have it write to bing then redeclare it:
              BufferedWriter out = new BufferedWriter(new FileWriter(w1));
              ...code to write out results and close...
              out = new BufferedWriter(new FileWriter(w2))
              ...code to write out results and close...
              Can you solve the PageRead.readPage("?") . I mean,

              I just want the example of the first file writer code of retrieving 1st element (1st Bing search result) and retrieving 6th element (1st Ask search result) from the queue.

              Read the 1st element(Bing 1st Result) and write out the content of 1st bing result into 1st textfile of bing
              tRead the 6th element (Ask.com 1st Result) and write out the content of 1st ask.com result into 1st textfile of ask.com

              so that The rest of 4 filewriter I can study the first file writer code example and do it myself.
              Check the code above, a queue doesn't work like this, you can only access the 1st element (and sometimes last) but never the middle. And you shouldn't open and close streams (FileWriters) when you don't have to as it is a waste of resources. Open it once, fire all your bing results in, close it, open a new one, fire all your ask results in, close it.

              A couple of things to note, after doing your first write to file your queue is going to be empty so you'll have to think of a way to make sure you still have a list of the results if you are going to write the same results to 10 files.

              Also your code:
              //Start 4 threads
              bingThread.start();
              askThread.start();
              writeBingThread.start();
              writeAskThread.start();
              isn't very safe as writeBingThread might go faster bingThread since they are both running at the same time meaning writeBing might end up trying to write before bingThread has got stuff ready for it!

              Comment


              • #22
                A good article, a compelling story requires the author to have a keen sense and eye to have an in-depth look at it. I am very impressed with your article. mapquest driving directions

                Comment

                Working...
                X