Daniel Perera wrote:Any hints?
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
fred rosenberger wrote:
Daniel Perera wrote:Any hints?
my suggestion would be to re-post the above code without that really long line so that it is easier for folks to read what you have.
Paul Clapham wrote:First change the printDir() method so that it returns a String which contains the desired information. You might also want to rename it, since it no longer prints a directory. In fact you might want to get rid of it entirely because writing to System.out is useless in a GUI application. Anyway getting back to the main idea: Change printDir() to return the string you want to see in your GUI. Then call the setText() method of the text component where you want that string to appear, passing the string.
Daniel Perera wrote:
Paul Clapham wrote:First change the printDir() method so that it returns a String which contains the desired information. You might also want to rename it, since it no longer prints a directory. In fact you might want to get rid of it entirely because writing to System.out is useless in a GUI application. Anyway getting back to the main idea: Change printDir() to return the string you want to see in your GUI. Then call the setText() method of the text component where you want that string to appear, passing the string.
I can't change the code as it is how it should be for the first part of my project, and in the GUI part I am supposed to use the methods in the first part, so I need to make it work with the system.out.println line...
Jeff Verdegan wrote:
Daniel Perera wrote:I can't change the code as it is how it should be for the first part of my project, and in the GUI part I am supposed to use the methods in the first part, so I need to make it work with the system.out.println line...
So, you're required to have a method that prints some stuff out to the console, even though it's a GUI app? And you're supposed to somehow also use that method to update the GUI? If that's how you interpret your assignment, I cannot suggest strongly enough that you go back and get clarification ...
Daniel Perera wrote:As you know, my printDir() method in the ArrayDirectory class does system.out.println for each of the entries within the array. I'm wondering how I could get the button to call this method but instead of printing the directory to the console, print it on to the JTextArea instead. [...] Any hints?
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Jeff Verdegan wrote:
Daniel Perera wrote:
Paul Clapham wrote:First change the printDir() method so that it returns a String which contains the desired information. You might also want to rename it, since it no longer prints a directory. In fact you might want to get rid of it entirely because writing to System.out is useless in a GUI application. Anyway getting back to the main idea: Change printDir() to return the string you want to see in your GUI. Then call the setText() method of the text component where you want that string to appear, passing the string.
I can't change the code as it is how it should be for the first part of my project, and in the GUI part I am supposed to use the methods in the first part, so I need to make it work with the system.out.println line...
So, you're required to have a method that prints some stuff out to the console, even though it's a GUI app? And you're supposed to somehow also use that method to update the GUI? If that's how you interpret your assignment, I cannot suggest strongly enough that you go back and get clarification, because that makes no sense at all. It makes less than zero sense. It is a net sense drain on the universe.
If that's not how you interpret your requirements, can you explain more clearly what they actually are, and what in particular you're having trouble with?
Daniel Perera wrote:
Okay, I must have misinterpreted the project. For part 1, we don't need a GUI, but I suppose I can just have my PrintDir() method return a string instead of having a print line. I will have a go at that now. I'll write back if I have any trouble..
Jeff Verdegan wrote:
Daniel Perera wrote:
Okay, I must have misinterpreted the project. For part 1, we don't need a GUI, but I suppose I can just have my PrintDir() method return a string instead of having a print line. I will have a go at that now. I'll write back if I have any trouble..
Okay, so if you're changing it to just return a String rather than printing it out, you should also change the name. It doesn't make sense to call something "printDir" that doesn't actually print anything. You could of course still define a method called "printDir" that first calls the method that generates the directory info as a String, and then prints out the results of that method.
a) Use a LinkedList to achieve the same tasks - completed this part
~ Mansukh
Mansukhdeep Thind wrote:Do you know what means? You are declaring an array hashDirectory whose component type is a List of Entry type objects i.e. :
This is not a List.
Mansukhdeep Thind wrote:
a) Use a LinkedList to achieve the same tasks - completed this part
Can you show me that code?
Campbell Ritchie wrote:Please restrict the length of your lines; long lines are very difficult to read.
~ Mansukh
Mansukhdeep Thind wrote:Never follow blindly what someone else is doing. Just because it works doesn't mean it is correct. You have stated that your assignment calls specifically for using a List to complete this task.
Isn't that so Daniel? And you ended up creating an array of List<Entry>? Aren't you supposed to use List for both line items a and b stated above?
My understanding is that you need to develop a List as follows:
and each of these Lists has to be hashed to a value respective to the starting alphabet of the surnames that it has. Am I interpreting your requirement correctly Daniel?
Campbell / Jeff / Andrew: Please pitch in and provide your inputs.
EDIT: I am unable to keep the posts short. When I quote Daniel's post, it becomes long.
Daniel wrote: so for example it might make sense to not create a list for surnames starting with A until a surname that starts with A is found - is this hard to achieve?
~ Mansukh
Mansukhdeep Thind wrote:
Daniel wrote: so for example it might make sense to not create a list for surnames starting with A until a surname that starts with A is found - is this hard to achieve?
The input file that you shared with me has surnames starting with all the alphabets, starting from A right up until Z, for sure. It is imperative that there has to be a List for each one, unless of course you have a use case in which you have an input file with surnames starting with only some alphabets.
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
John Pickles wrote:Fair enough, so how will I ensure that the entries are added onto the correct lists?
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|