Jonathan Haybok

Greenhorn
+ Follow
since Mar 12, 2009
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jonathan Haybok

This seems like such a simple question, but I often have trouble separating code out into different methods. For example, if I want to parse an XML file, I would most likely end up with one big block of code inside a class' constructor. I don't know when to separate out functionality in a method. Is there a simple rule to it? Can you guys give me any advice on how to better organize the information?
9 years ago

Wouter Oet wrote:What is your definition of a data file?


I'm actually looking at a job listing, so I'm not exactly sure, but I assume it means a data file coming from a database. The listing says the job involves developing parsing routines to convert various types of data files into a generic data model for storage. Hope that's clarification enough for you.

Thanks for clearing the terminology up Paul. I guess I want to parse the data file, then serialize that result into an XML document.
9 years ago
Can someone point me in the right direction on where I would find a good tutorial (or any information at all) on how to do this? I know about parsing an XML file using SAX and DOM parsing, but what about parsing a data file to XML?
Then can someone tell me why this isn't removing carriage returns when writing to a text file? I'm new to I/O.



9 years ago
Thanks for clearing that up. I had to think about it for a little bit, but I guess the whole point is to choose the variable type that fits your needs and provides the most flexibility based on those needs.

It would be bad if I were to have a big program that casts List references to an arraylist, because I would then have to go back and change all those casts if I decided to instantiate the reference to another type of list.
9 years ago

Stephan van Hulst wrote:Yes, if you use the shipments variable without casting, you will only be able to use the methods declared in the List interface.

This is usually the preferred way to do it. Are there methods in ArrayList that you want to use?


No, not in this case. But if I wanted to, how would I do it? Would I have to explicitly declare the variable as a reference to an ArrayList or could I cast the object somehow since I know it's really an ArrayList. I tried casting, but that doesn't seem to work. I just want to make sure I understand what is really happening here, because it doesn't seem to work the same as casting with regular objects.
9 years ago
List<Shipment> shipments = new ArrayList<Shipment>();

Simple question here (I think). Since the statement above declares the shipments variable as a List of type Shipment, but associates it with an instantiation of an ArrayList of type shipment aren't we only allowed to call methods that are associated with the List interface? Aren't there additional methods in ArrayList? How would you cast shipments to an ArrayList, or does that even make sense?
9 years ago
Awesome! Thanks for the thorough explanation. I knew java was pass-by-value, but I guess the notion took a while to sink in. The static declaration makes sense to me too now.
9 years ago
I had some issues with the count variable when making this Hailstone Sequence application. I got it to work, but am wondering if someone can explain the scoping issues involved with increasing count in the displayNext() method. Debugging shows that the count resets to 1 every time the while loop iterates. How would I allow the displayNext() method to properly set the variable (instead of my compromise of just iterating count within the while loop)?
9 years ago
All I want to do is store patterns that are imported from a text file. The text file would be simple asterisks that would signify an alive cell (cell with a filled background). Spaces would be just be cells that are not alive. I'm sure many of you know about the Game of Life (I've been told it's the most programmed game), and that's what I'm doing.

I have a grid that I create with 2d arrays. I fill cells in the grid by using another 2d array that just stores true/false values. So I just need to figure out how to map an input stream of character/spaces to indexes of an array.

Can anyone help me out with this? I'm having trouble figuring out how the input stream identifies characters, and how, for example, to extract the values of an asterisk that would correspond to array[0][0]. What equates to rows/columns in text files? I apologize ahead of time for my poor description of the problem. Hopefully someone understands it.

I know I will have to modify this block of code:
10 years ago
Seems like I'm missing something here...

I tried changing them to floats, but then that was incompatible. So I tried this other format, which doesn't work.

ERROR: Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 9

11 years ago
I wrote this out, and get this: "AWT-EventQueue-0" java.lang.IllegalArgumentException: Color parameter outside of expected range: Red Green Blue"

11 years ago
I can't seem to figure out how to fill the polygons I made with random colors. My assignment specifically says to generate 10 random colors, use an array to store the 10 colors and then use the colors to fill the ten polygons I made. Right now my array seems to just hold numbers between 0 and 255, and I don't know how I would set up the 10 RGB sets.

Lines 57 to 66 is where the specific code is.

11 years ago

Eric Daly wrote:Ok, then do you know how to do it using System.out.println? It looks like you only have to display the info once, which means you don't really have to do a Swing gui and get data from another class more than once. Do you know how to use a JOptionPane? Here's the API from Sun. Here's how you can use it:

and here's Sun's tutorial on it.



Thanks for your help. I should have mentioned that the project specifically states that I need to use a GUI layout manager.

I'm just now realizing that my average comes out as 0 in every single case. As you can see I needed to overload two methods to get an average, but for some reason it's wrong?
11 years ago
Here are my other 2 classes. I've never done a getString() method, how would I use it? The very last comment is where I'm having the bulk of my trouble:



11 years ago