Kurt Van Etten

Ranch Hand
+ Follow
since Sep 07, 2010
Tallahasse, FL
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
3
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Kurt Van Etten

I'm new to machine learning and have only a vague idea of what it encompasses. In looking through the table of contents of "Machine Learning in Action", it seems like it contains an assortment of seemingly unrelated techniques for solving certain types of problems. What I'm wondering is if there is an overarching theme or philosophy which unites these different techniques together? Thanks!
9 years ago
Hi,

In your program line: you've got one too few "=" in your R3 comparison, so it is actually an assignment. This is a fairly common newbie error. One nice thing about Java is that it will catch this kind of error at compile time. In a language like C or C++, the assignment R3 = 0 will be treated logically as false no matter what value R3 had going into the expression. (It looks like you may have some other syntax errors in your code as well, but one at a time!)

By the way, one of the things the FAQ may mention is that you should surround your program excerpts in code brackets (you can use the button at the top of the message editor). That will display your code with formatting for easier reading.
10 years ago
Hi Ganesan,

What kind of background should someone have to make the best use of the Training Lab? Could someone who is relatively new to Java use it as a learning tool, or would that just cause a lot of frustration?
Just completed assignment OOP-4. Woo-hoo! (It might be a little while before I'm ready to submit Servlets-1.)
10 years ago
Ah, now that you've got it compiling, it's time for the joy of logic (runtime) errors!

While I think that there is some benefit to decomposing your program into a number of distinct methods, your current version is a lot simpler than what you had before. One stylistic change I would suggest is to use a while loop instead of a do-while. (I think that should work without needing any other changes.)

While you're at it, take a close look at what's in the body of the loop. You've repeated a line, and that's probably what's causing your current problem.
10 years ago
Hi Karine,

The spacing does make it easier to read, but what I was referring to earlier was the method declaration that stretches across the page. If it looks okay in your editor then that's fine for your own use, but when you post your code here in the forum it makes it hard to read because you have to pan back and forth (unless perhaps you've got a very big monitor).

For your remaining error messages, look at this snippet:

When you call nextToken(), what exactly do you want to call it on?
10 years ago
By the way, you may want to break those calls to the tokenFile and reportSorted methods into multiple lines. Having it stretch across the screen like that makes it hard to read. (And because of the way that text flows in the forums, it makes everything else hard to read as well.)
10 years ago
Regarding the first (repeated) error, do you see anything different about how you've declared the tokenFile method compared with the other methods you have?

For the other error, unlike in languages like C++, Java requires that boolean expressions or variables be used in contexts where a logical value is expected. So in your if statement,

you have to make the stuff between the parentheses into a boolean expression--easy enough to do with a =, < or > 0 as needed.
10 years ago
Hi Karine,

Just looking at the section of code you've commented out...

First off, you made a little typo in your for statement. (Just take a look at that line, it should jump right out at you.) That should at least get your code running for you. Secondly, think about your StringTokenizer and where you should be initializing it.
10 years ago
Hi Victor,

From the API docs for the flush() method of the Writer class,

If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.


So even though the JVM is writing out the characters immediately, the underlying OS may still be buffering them. I suspect that if you experiment with different amounts of text being written out, you'll find a point where the two classes start behaving differently from each other. Even when there is no observable difference in the outward behavior of the two classes, the BufferedWriter I/O could still be more efficient if it results in fewer calls to the OS being made.
10 years ago
Can I add to Vivek's question? This is something I've been wondering about too. For some of the IO classes, the close() method can throw an exception. However, putting another try/catch block inside the finally block, or nesting try/catch/finally blocks in some other way, seems awkward. What is the preferred way of handling this situation?
10 years ago
Congratulations Gillian!
10 years ago
Hi Wouter, I had actually at first written in my response that Pan might want to look at the Character isDigit(), isLetter(), and isLetterOrDigit() methods. I changed what I wrote because it looked like the problem was specifically requiring ASCII character ranges. It's certainly worth being aware of this, though, for situations where you want to allow for correct internationalization.

Pan, you're right that Jesper's approach is better than mine, both in terms of efficiency and conciseness of code, if you're familiar with regular expressions. (Of course, behind the scenes the regular expression matching is still scanning along the input String character by character, but it's likely to be doing it much more efficiently than some routine you've manually coded.)
10 years ago
You don't really need to convert the String to a char array, since the String charAt() method allows you to look at the individual characters one by one. In any event, there is a standard programming trick for doing this type of thing: the numeric values for the digits '0' through '9' appear in order in the ASCII sequence, and likewise for the alpha characters 'A' through 'Z'. Since chars can be used like numbers in expressions, this allows you to use <=, =>, etc. in your code to determine if the chars in the ID meet your criteria.

10 years ago
Hi Shuba,

IOException is located in java.io, so the fully qualified name would be java.io.IOException (and the program will compile successfully if you make that change). That is not the only thing that is fishy with this code, though.

By the way, if you're not sure where something like this is located, you can go to the Java API docs, click on "All Classes" in the top left frame, and then scroll down the list to find the item you're looking for.
10 years ago