Announcement

Collapse
No announcement yet.

Requesting help on Java Programming

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

  • Requesting help on Java Programming

    Hello,

    Is there any game hacker who is good at java programming?

    Because I have a java assignment using Netbeans which I don't know how to do do.

    Lazy Bastard allowed me to post this thread here.

    Can anyone give me some pointers or step by step guide on how to complete this java assignment?
    Last edited by silentkiller; 07-29-2011, 05:54:28 AM.
    Keep Smile + Let's be together !! + Magical Glasses + Cowabunga + Superhero + Maximum Carnage

  • #2
    It's been a while since you posted this, just wondering if you got it sorted? I can point you in the right direction if you need

    Comment


    • #3
      Personally I prefer JCreator, to me it's more user friendly than NetBeans.

      Comment


      • #4
        Originally posted by cYs Driver View Post
        It's been a while since you posted this, just wondering if you got it sorted? I can point you in the right direction if you need
        I already sorted that out but I have one more java question to ask you.
        Last edited by silentkiller; 07-29-2011, 05:55:24 AM.
        Keep Smile + Let's be together !! + Magical Glasses + Cowabunga + Superhero + Maximum Carnage

        Comment


        • #5
          Originally posted by Gtlcpimp View Post
          Personally I prefer JCreator, to me it's more user friendly than NetBeans.
          Do you know how to solve this java assignment?
          Last edited by silentkiller; 04-16-2012, 06:51:56 PM.
          Keep Smile + Let's be together !! + Magical Glasses + Cowabunga + Superhero + Maximum Carnage

          Comment


          • #6
            What part are you stuck on exactly? I've had a read through and it looks quite long for someone to actually go through and post a whole solution so maybe you could narrow it down, is it the threads? Sending queries to a webpage? Getting the results (I think the provided library takes care of that for you)?

            I should be able to help or at least point you in the direction of good tutorials for the parts your stuck with.

            Comment


            • #7
              Originally posted by RyanfaeScotland View Post
              What part are you stuck on exactly? I've had a read through and it looks quite long for someone to actually go through and post a whole solution so maybe you could narrow it down, is it the threads? Sending queries to a webpage? Getting the results (I think the provided library takes care of that for you)?

              I should be able to help or at least point you in the direction of good tutorials for the parts your stuck with.
              Ok, I will just narrow it down part by part

              It is using thread , Sending queries to a webpage and getting the result.

              1st part (how to make it like when the user run the (JFRAME) GUI in netbeans and enter the search string GSHI in textbox , click on the search button and it will return the top 5 search results.

              I mean getting the query string highlighted in red and add to the library class to display search result
              example for bing format

              1)How to put the search result content of system.out.println(pageRead(bingsearch)) and system.out.println(pageRead(asksearch)) and system.out.println(pageRead(altavisasearch)) into three different jtextareas?
              Last edited by silentkiller; 07-29-2011, 05:56:14 AM.
              Keep Smile + Let's be together !! + Magical Glasses + Cowabunga + Superhero + Maximum Carnage

              Comment


              • #8
                Ok I’ve had a look at what you’ve got so far and you’ve got the right idea but there are, as you know, a few things missing. I’ll take it questions by question.

                1) Allow user to enter the query terms, for finding out the top ranked relevant websites.

                You do this but not in the format expected by the website. What you need to do is grab all the terms entered in the search box as you have done but then change it so that rather than the terms being separated by a space in the url they are separated by what the search engine expects (for bing it is a plus sign +)

                You can do this by using the method replace which is part of the String class. So the line:

                querystring = querystring.replace(“ “, “+”);

                would replace all the spaces with pluses. You might want to use String.trim() as well to get rid of any spaces that might be at the end of the String and obviously if the other search engines want something else for joining then you’ll have to replace + with whatever they want.

                2) Your application will create 2 separate threads which will query and look for results from the 2 search engines (bing and ask.com) simultaneously.

                Your program isn’t doing this at all. Threads are really a topic all on their own but basically the impression I get is that you need to create a class which extends thread and carries out the querying. Check out this tutorial http://download.oracle.com/javase/tu...ncy/index.html for more about it and if you are completely lost let me know and I’ll try help out.

                3) Program will analyze the downloaded html source from search engine site to find out the top 5 queries. You would have to look for the specific pattern to retrieve the web site address eg http://.... as a pattern. You will need to apply suitable regular expression checks to find such patterns.
                (Hint: for bing, you can look into the ¡°<cite>¡± pattern for a guide to find the relevant web site, and for ask.com ¡°<a id=¡°r¡± as helpful patterns)


                This question is a little unclear, he asks for the top 5 queries but what I think he means is the top 5 results. Basically you’re just searching the string that is returned by the ReadPage method and outputting the first 5 substrings that start http:// (assuming of course there isn’t any that are returned as part of the page in which case you’d need to skip those ones).
                There are a few ways to do this but I’d probably go with splitting the string on spaces using String.split(“ “); and then iterating through the returned array to find a string that starts http:// and add the first 5 that do into the queue made for the next question.

                4) These UNIQUE webpages urls will be queued to a Queue datastructure.(Note that the 2 search engines may show the same website)

                They could just as easily be added to an array but meh, if he wants a queue give him a queue. So declare a Queue object LinkedBlockingQueue bingResults = new LinkedBlockingQueue(5) and add all the first 5 results to it. Of course you’ll have to do this for each search engine unless you go with 1 big queue in which case you’ll need to keep track of which result was returned by which engine assuming you need to separate them out again.

                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)

                You’ve got a BufferedReader there already so you have some idea about this. Writing works the same way, define a file using the File class, define a writer using something along the lines of StringWriter and have the writer write to the file. Again you need to do this in threads so make it part of the query thread above if you get that going.

                6) The 2 threads will process the next available and unprocessed web url once it has finished its current task. They will keep doing so, until all the provided urls are processed.

                Ok this makes me think the thread is meant to go through the queue writing out the results so make it do that.

                7) The website urls, html page contents should be shown to the user through a GUI The website urls should be displayed in a listing in ascending order.

                Does he want the pages rendered in the gui or just a list of the urls? Ascending order of what, name or rank? Assuming it is just a list of strings in order of rank they will already be in order in the queue but be careful as the queue works on the FIFO principle so the first one you put in (the highest ranking) is the first one you’ll get out so take care not to reverse them when adding them to the list.
                I noticed in your code you’ve wrote a readPage function. You shouldn’t need to do this as the assessment says it is provided for you in the library he attached so just add that to your libraries and you should be able to call his method as if you’d wrote it yourself in your code.

                Sadly I don’t have an internet connection on my laptop at work so can’t test anything out but the above should all work. The main problems will be getting your threads working and keeping things synchronized with access to the queue(s) so spend some extra time on those parts.

                Let me know if this helps or if there are still parts that are bothering you. Also what level is this, 1st year uni, 2nd, 3rd? That will change how much work is expected and hence the solution to each part.

                Comment


                • #9
                  Sorry I neglected to answer your actual questions!

                  I mean getting the query string highlighted in red and add to the library class to display search result example for bing format

                  You don't need to highlight it in red or any other colour so I wouldn't bother, it won't get you extra marks and will just use up time.

                  I mentioned above to use the library provided by just adding it to the libraries for the project (Properties -> Libraries -> Add Jar) and then you can call the method like you wrote it yourself. The one you have wrote works though, I just tried it by copying the JAR onto the networked computer, but for the sake of the assessment you might as well use the one provided unless you think it'll get you extra marks showing you wrote one yourself.

                  1)How to put the search result content of system.out.println(pageRead(bingsearch)) and system.out.println(pageRead(asksearch)) and system.out.println(pageRead(altavisasearch)) into three different jtextareas?

                  pageRead returns a StringBuilder but jTextArea.setText takes a String so just call the .toString() method on the StringBuilder i.e.

                  jTextArea.setText(StringBuilder.toString());

                  It'll look ugly as hell but it'll work. To make it prettier you can look into classes related to formatting (Called Formatter surprisingly but it can take a while to get formatting looking pretty so if it's not important don't spend too much time on it)

                  Comment


                  • #10
                    I still can't figure out about the thread class, can you tell me what are necessary methods in order to make 3 threads since I have 3 search engine?
                    Last edited by silentkiller; 07-31-2011, 09:43:00 AM.
                    Keep Smile + Let's be together !! + Magical Glasses + Cowabunga + Superhero + Maximum Carnage

                    Comment


                    • #11
                      I'm at work just now but will try and fire something out later tonight that does it.

                      Basically your looking to make a class that extends Thread and has the methods for doing the searching and returning the results. When the user hits the Search button 3 of these classes are created, one for each search engine, and they each connect and return their results somewhere before dying off and the results are then shown.

                      Some 'off the top of my head' code

                      public class SearchThread extends Thread{

                      private String query;
                      public SearchThread(String query){
                      this.query = query
                      }
                      public String search(){
                      //code to connect and send your query which returns the results
                      }

                      public void run(){
                      search();
                      }
                      }

                      That is your Thread class, so when the user clicks submit you'd create 3 of these with the query strings and run them to get the results. I can't remember the proper way to write the run() method so you'll need to look at that or wait till later and I'll fix it.

                      You'll also need to make sure the place the result are returned to is syncronised or you'll find the threads can overwrite one another or create other strange results.

                      So your main gui class would have things along the lines of

                      public class gui extends JFrame{

                      public syncronised String results = ""; //a global variable for the class that will store all the results. If you prefer you could have 3 of these, one for each set of results.

                      ...//the rest of your gui code

                      searchButton.OnClick(){
                      SearchThread Bing, Ask, ThirdOne;
                      Bing = new SearchThread(bingQuery);
                      Ask = new SearchThread(askQuery);
                      ThirdOne = new SearchThread(thirdQuery);
                      results.append(Bing.run());
                      results.append(Ask.run());
                      results.append(ThirdOne.run());
                      //then code to display results
                      }

                      Like I've said this code is just along the lines of what you are looking to do and I know the run method isn't quite right (for one it returns void when we later use it expecting a string) but there should be enough here to get you going.

                      Comment


                      • #12
                        Right, ignore the way I was doing the thread before because as soon as the thread is finished processing it dies off and you can't access the data anymore. Instead pass a reference to the text box to the thread and have it write to it once it's got its results.

                        Check out the attached file for some actual, working code.
                        Attached Files

                        Comment


                        • #13
                          Originally posted by RyanfaeScotland View Post
                          Right, ignore the way I was doing the thread before because as soon as the thread is finished processing it dies off and you can't access the data anymore. Instead pass a reference to the text box to the thread and have it write to it once it's got its results.

                          Check out the attached file for some actual, working code.


                          3)Program will analyze the downloaded html source from search engine site to find out the top 5 queries. You would have to look for the specific pattern to retrieve the web site address eg http://.... as a pattern. You will need to apply suitable regular expression checks to find such patterns.
                          (Hint: for bing, you can look into the “<cite>” pattern for a guide to find the relevant web site, and for ask.com “<a id=“r” as helpful patterns)

                          About part 3, I know that this one need to create arraylist but I don't know use which one to use is it using hashmap or hashset and also regular expression?

                          Here are some of the codes that I had done, I know it is not correct, need to modify.

                          public class SearchEngineGUI extends javax.swing.JFrame {

                          HashMap<String, ArrayList> hm = new HashMap<String, ArrayList>();





                          ArrayList<String> a = new ArrayList<String>();

                          String bingsearch = "";

                          while ((text = br.readLine()) != null) {
                          text=text.trim();
                          if (text.equals("</cite>")) {
                          hm.put(bingsearch, a);
                          //System.out.println(bingsearch);
                          a = new ArrayList<String>();
                          } else if (text.charAt(0) == '<cite>') {
                          bingsearch = text;
                          } else {
                          a.add(text);
                          if (hm.containsKey(text)) {
                          ArrayList B = hm.get(text);
                          B.add(bingsearch);
                          } else {
                          ArrayList<String> C = new ArrayList<String>();
                          C.add(bingsearch);
                          hm.put(text, C);
                          }

                          }
                          Last edited by silentkiller; 07-29-2011, 10:57:13 PM.
                          Keep Smile + Let's be together !! + Magical Glasses + Cowabunga + Superhero + Maximum Carnage

                          Comment


                          • #14
                            An ArrayList is a class on its own so it isn't really a question of whether to use a HashMap or HashSet, if you have to use an ArrayList then use an ArrayList!

                            A regular expersion, as far as this project is concerned, is just a String that you can search for to work out where the results are in all the HTML your getting back from the query. In this case it recommends "<cite>" for bing and "<a id=\"r" for ask. So you search through the query looking for those terms and grab the web address that appears after them and add it to your ArrayList.

                            What you could do, and it looks like you were trying to, is have a HashMap of ArrayLists where the search engine name is the key and the ArrayList is all the results so to get a set of results out you'd say HashMap.get("bing") and it would return the ArrayList of web addresses.

                            As for your code, sorry to say this but its a mess . I'll list a few things here but it's all a bit jumbled and doesn't look like it quite knows what its meant to be doing. First off be sure to use useful names for variables so you (and other people) know what they are for, resultsStore is a lot more useful than hm. You are using bingsearch as a key but never setting it to anything other than "" so each result will be overwritten in the HashMap at hm.put(bingsearch,a). Not that it will ever get there as there is very little chance the line read from br will equal "</cite>", it might contain it but equals and contains are very different. text.charAt(0) compares the first letter so can't be used to compare against a String and even then you should use .equals(String) and not ==. I'll leave it at that

                            Btw if you are using the Thread class I sent or something similar this will need to go in there so it can access the results, unless you read them back from the textBox or pass in something else (like a string) to store them.

                            Also why are you doing 3 search engines when the question only asks for 2?

                            Comment


                            • #15
                              I thought I can add it as a extra feature but I realized that I can't find regular expression for that altavista search engine for part 3.
                              I removed the altavista search engine.

                              Here is what I done:

                              I put the regular expression checking method inside main method in thread class.

                              I didn't put hashmap codes inside.

                              But I don't know how to combine hash set, arraylist and the regular expression to display the requiremment of this java assignment.

                              Please help me to complete my java assignment I mean the whole assignment if you can solve.


                              As a return of favour, I will help you make a trainer or cheat codes for older games if you requested.
                              Last edited by silentkiller; 07-31-2011, 09:44:53 AM.
                              Keep Smile + Let's be together !! + Magical Glasses + Cowabunga + Superhero + Maximum Carnage

                              Comment

                              Working...
                              X