Jeff Jetton

Ranch Hand
+ Follow
since Mar 29, 2005
Merit badge: grant badges
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jeff Jetton

Originally posted by Edwin Keeton:
All the answers are probably not in a single book.


But an astounding number of answers are in Code Complete, by Steve McConnell.

The fact that one of the best books on well-written software comes from Microsoft Press is an irony not lost on me.

- Jeff
17 years ago
Good advice from Fred. I'd also suggest that you break the problem down into smaller problems.

For example, how would you simply print out the first 100 numbers? Don't worry about adding them up or anything at this point.

Once you get that figured out and working correctly, then work on summing them up.

Good luck!

- Jeff
17 years ago

Originally posted by jerry andy:
1.polymorphysm vs encapsulation.
3.abstract vs inheritance
4.Hash Map
5.Array List
6.Hash Table vs vector

Could you give us some idea of what parts you're having trouble with? What questions, specifically, do you have about these concepts?


- Jeff
17 years ago
Yes, generally, in Java, the reference to the screen's Graphics object (called "g" in this case) is not reliable outside of the paint() method.

Standard procedure is to do all of your drawing in the paint() method, or in methods that are called only by paint(). That drawing code should look at the state of your application to know what to draw.

For example, you could have your key press set a boolean variable. Then, when paint() did its thing, it would look at the variable to know whether or not to draw the image.

And you don't normally call paint() directly. As Svend said, you would usually call repaint().

- Jeff
19 years ago

Originally posted by Jeff Bosch:
What makes this seemingly-trivial problem urgent?

LONDON (Reuters) - The British Security Service, in a rare press conference, has announced that they are finally calling off the search for Agent 0x007, whose real name can now be unveiled as being Manuel Diaz.

"When last we heard from agent Diaz," Director-General Eliza Manningham-Buller said, "he was deep undercover, infiltrating a terrorist network in the Middle East. That was three weeks ago."

Diaz's mission involved the strategic use of computer documents that were supposedly from Canada, but were actually forgeries from the United States.

"Unfortunately, we found out that there were many, many words ending in 'or', instead of the preferred Canadian and British ending of 'our'," Manningham-Buller continued, "Our only hope now is that Diaz was somehow able to find a way... any way... to quickly convert those documents before his cover was blown."

This is the first such mishap in MI5 history since the notorious "Hello, World!" fiasco that claimed the lives of double-agents Brian Kernighan and Dennis Ritchie.
19 years ago
There are at least two ways to do this, by the way. One is to reverse the original string and see if it's the same, which is what Mr. Diaz has spelled out for you in vivid detail.

Of course, since that first way has already been spoiled, I'm sure you're now looking for a cool, different way to do it that you can figure out on your own, right? So try this algorithm on for size:

Compare the first letter to the last letter. If they're not the same, you're done--it's not a palindrome. If they are, look at the second letter and the second-to-last letter (if they exists) and check to see if they're the same. If they are, move to the... well, you get the idea.

Eventually, if it's a palindrome, you'll get to the middle of the String (which can be tricky to determine, since Strings can have an odd or even number of characters). If it's not, you'll eventually find a pair of letters that doesn't match.

For longer phrases in particular, this will probably be a more efficient test than reversing the entire string and checking every letter for equality.

- Jeff
19 years ago
Check out Fred Grott's emulator collection (which, incidentally, I discovered by following the "J2ME Tech Tips" link at the top of this forum).

- Jeff
19 years ago
The book that I mostly learned from, and that I keep referring back to, is John Muchow's "Core J2ME Technology & MIDP", which is published by Sun.

It does not cover MIDP 2.0, however. But that's no biggie for me, since I like to program to the "lowest common denominator" anyway. If you must have 2.0 coverage, the Knudsen book is a good way to go. I have it also.

- Jeff
19 years ago

Originally posted by Kalyani Marathe:

I have question related to char value.

char c = -0; // why no compiler error.
System.out.println(c);//it prints nothing


When you assign -0 (an int) to a char variable, the compiler casts it to the char represented by the ASCII value of the int. (Well, the UNICODE value actually, but it's the same in this case.)

Really, all a char is is an unsigned, 16-bit integer anyway. "Behind the scenes", it's just a number being stored. In this case -0 is the same as 0, which is the ASCII value for "NULL". (Not a null reference--that's something different.)

So your println() is printing exactly what you're telling it to. It's just that you're essentially telling it to print nothing.

- Jeff
I'll give you a hint:

The ASCII code for a question mark is 63. What line in your code might be printing the numerical representation of a letter by mistake?

- Jeff
19 years ago

Here's a good "geek" story... Years ago, I had a roommate that had just dropped an intro to programming class at Boston University. I bought his textbook off of him, had him give me his username and password for his mainframe--yes, mainframe--account, and would sneak into the BU library to get on a terminal (I wasn't a student there). That's how I started to teach myself C.

The textbook was the original, 1987 edition of "C: The Complete Reference". It's still one of my first resources I'll grab when I have to freshen up on linked lists, expression parsing, etc. In fact, it's sitting on my office bookshelf as I type this.

So thanks, Herb! Glad to have you at the ranch.

- Jeff
19 years ago

Originally posted by Max Simpson:
doesn't calling 'return' cause the method to exit immediately, regardless of whether or not it is called from within a loop?

As others have said, there are cases where "return" doesn't return right away. But I doubt that's the problem here.

It sounds like you might be confused on what "return" returns from. It will cause the method to exit, but it's the method that the return is in. In other words, your function that prints "Done" is what the return will exit from. And when it exits, it winds up right back at the loop your function was called from. That method (the one with the loop) is not at all affected by the return that's in your "Done" method.

- Jeff
19 years ago

Originally posted by Ta Ri Ki Sun:
It seems to me that you're looking at the whole picture and worrying too much, it's much simpler when you look at all the rather specific little problems.

I agree.

Are you familiar with creating your own classes and intantiating them as object? You should have that down cold before you start worrying about inheritance.

So, if you haven't already, try just doing the Student class first. Get so that you can define your class, create a new object (or objects) based on that class, assign various ID and GPA values to it, print those values out, and so on.

Then, and only then, should you tackle the CollegeStudent class.

Which might lead you to wonder: Why do all this inheriting in the first place? Well, the idea here is that you need a special type of Student that has the ability to hold a Major. Now, in the dark old days before object-oriented programming, we would have to rewrite our Student class. But in Java, we simply need to create a new class (a subclass) that has the Student class as a "parent". We add just the new functionality to our subclass, and it magically gets all the functionality of the Student class "for free".

In theory, someone else might one day write a "ElementarySchoolStudent" class that also inherits from Student. It won't have a Major (that's just in your CollegeStudent subclass), but it might add the ability to store a SchoolBusRouteNumber, or it might have a method that sends a report card to the parents. Someone else might write an "AdultEducationStudent" that would have still other functionality... you get the idea.

And if it turns out that, for example, you one day need to store and track the GPA as a percentage instead of a 0.0-4.0 number, all you have to change is your parent class, Student. The subclasses will then automatically use this new way of dealing with the GPA--you won't have to change them at all.

- Jeff
19 years ago

Originally posted by Chengwei Lee:

Firstly, it was you to declared that the return type of this method to be of String type. And at the return statement, you concatenate String object with the integer & double results which in turn produced a new String object.

Yup. Another way to look at it is to rewrite your code like this:

Now ask yourself: What would you have to put in place of "???" to make this work? In other words, what type should the variable "foo" be?

A String, of course. That's really what you're returning, even though your example doesn't use a variable as an intermediate step like I'm doing.

- Jeff
19 years ago

Originally posted by Francisco Gonzalez:
I know you ended up with the right answer, but is that always going to work ?

No, it won't always work. It did happen to work in this case, whether by luck or by clever foresight and optimization on the part of Steven.

The key is that final (y & 7) operation. "Anding" something by 7 effectively masks off all but the last three bits of the result, so even if you got bits 4 and up completely wrong, it wouldn't matter in this particular question.

- Jeff