View Single Post
Old 11-22-2004, 07:37 PM   #14 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,175
Belisarius is on a distinguished road
Taking the SQL first, you seem to have a decent handle on it. I haven't had the need to explicitly use JOINs, but that looks about right from my understanding (this is why you post SQL stuff in the SQL forum; get more eyes looking at it that know what they're doing). Not sure what the brackets are for though. As for selecting a specific author, the LIKE keyword should do, or you can explicitly say:

lastName=’Nieto’

As for the palindrome stuff, let's see.
Code:
public Lab6()
You need to make it at least:
Code:
public Lab6(){}
to get past parsing.

Code:
{
string=JOptionPane.ShowInputDialog("Enter a string: ");
}
You must have come from C programming. In Java, you don't randomly insert brackets, like you do in C. This would, I believe, fail parsing. Further, the "s" in "ShowInputDialog" needs to be lower case. In Java naming conventions, the first letter of a method is almost always lower-case.

Code:
{
string=JOptionPane.ShowInputDialog("Enter a string: ");
}

//add object to stack
stack.push(string);

//remove object from stack
stack.pop(string);
string=new String string1
None of this is contained in a method or constructor. You'll have all sorts of syntax errors if you try to compile this.
Code:
string=new String string1
This doesn't make sense. If you want to set "string" equal to a new String, then it should be
Code:
string = new String(); // or
string = "";
If you want to declare "string1", you should say
Code:
String string1 = new String();
Code:
public static void main(String args[])
This method needs brackets. All methods, unless they're being defined in an abstract class or in an interface, probably should have brackets enclosing code.
Code:
if (string=string1)
This is a no-no in Java. First off, comparison is done with ==, not =. What you have actually done here is set string equal to string1, the result of which will always be true.

Further, you don't want to use "==" most of the time, because what you're doing is comparing the memory locations of the objects, not their values. I can create two different instances of "foo", and a "==" will return false. What you want is to use the ".equals()" method. That will return whether or not the two strings are equal in the traditional sense (whether or not they have the same characters).

Also, I assume you're going to refine your methodology because what you're doing won't actually tell you if you have a palindrome or not. In fact, apart from the reasons I mentioned above, what you're trying to do will always return true; because you are attempting to compare a String to a copy of itself.

Finally, and while I had never tried it before, your method of getting input works just fine. It's almost as simple as getting it from the command line.
__________________
GitS
Belisarius is offline   Reply With Quote