hello...this is my firt post...
i need your help in this one...im doing a palindrome program...
"application that reads in a five-digit integers and determines whether
or not it is a palindrome. if the number is not a five-digits long. displays
an error message dialog indicating the problem to the user.when
dismisses the error dialog, allow the user to enter new value. Using
GUI cotrols..."
thats it...thanks
Okay. You have our permission to get working on that.If you have been working on that and are stuck in a specific place then please post formatted code with what you have so far and ask a specific question about what problem you are having.
> And your problem is?That was a question to the OP, of course...
Hint:- use pencil and paper to find out what you want your program to do, step-wise- look at String and for loops or StringBufferAlso, look at the Swing tutorials. And probably your lecture notes.
Different kido, same question!There must be a classroom present.Show us some work and we'll help you with specific issues,
You cna do the swing part on your own. I don't know any of that stuff.
import java.util.Scanner;
public class Caller
{
private static final int PALINDROME_LENGTH = 5;
public static void main(String args[])
{
Scanner in = new Scanner( System.in );
String userInput = "";
do
{
System.out.print( "Enter your palindrome of length "
+ PALINDROME_LENGTH + ": " );
userInput = in.nextLine();
if ( userInput.length() == PALINDROME_LENGTH )
{
if ( isPalindrome( userInput ) )
{
System.out.println( "Your number " + userInput
+ " is a palindrome" );
}
else
{
System.out.println( "Your number " + userInput
+ " is NOT a palindrome" );
}
}
else
{
System.out.println( "Invalid length" );
}
}
while ( !userInput.equalsIgnoreCase( "exit" ) );
}
private static boolean isPalindrome(String s)
{
int halfLength = (PALINDROME_LENGTH - 1) / 2;
char[] chars = s.toCharArray();
for ( int i = 0; i < halfLength; i++ )
{
if ( !(chars[i] == chars[PALINDROME_LENGTH - 1 - i]) )
{
return false;
}
}
return true;
}
}
> You cna do the swing part on your own. I don't know> any of that stuff.Do you think you are helping?
kajbja at 2007-7-14 23:32:46 >

I must also add that the previous code only works for odd length plaindromes.
Use this method and it'll work for even and odd ones. Sorry I forgot about that...silly me.
private static boolean isPalindrome(String s)
{
int halfLength = 0;
if ( PALINDROME_LENGTH % 2 == 1 )
{
halfLength = (PALINDROME_LENGTH - 1) / 2;
}
else
{
halfLength = PALINDROME_LENGTH / 2;
}
char[] chars = s.toCharArray();
for ( int i = 0; i < halfLength; i++ )
{
if ( !(chars[i] == chars[PALINDROME_LENGTH - 1 - i]) )
{
return false;
}
}
return true;
}
> > You cna do the swing part on your own. I don't> know> > any of that stuff.> > Do you think you are helping?No, he's a big-time grudge holder and thinks he's ticking me off.
> He's a true buddy> ;)That's a foe in disguise.
> > Do you think you are helping?I sure do. Hey, I don't know swing at all. She still has to do that part.
> > > You cna do the swing part on your own. I don't
> > know
> > > any of that stuff.
> >
> > Do you think you are helping?
>
> No, he's a big-time grudge holder and thinks he's
> ticking me off.
Now, *this* is amusing. :o)
> > > > Do you think you are helping?> > I sure do. Well you arent.
> I must also add that the previous code only works for
> odd length plaindromes.
>
> Use this method and it'll work for even and odd ones.
> Sorry I forgot about that...silly me.
Why not change it to..
public static boolean isPalindrome(String text) {
return text.equals(new StringBuilder(text).reverse().toString());
}
Kaj
kajbja at 2007-7-21 11:03:01 >

> I must also add that the previous code only works for> odd length plaindromes.> > Use this method and it'll work for even and odd ones.> Sorry I forgot about that...silly me.Yes, silly you.
> >
> > Do you think you are helping?
>
> I sure do. Hey, I don't know swing at all. She
> still has to do that part.
How much do you think the OP is learning if he doesn't give it a try on his own? The only thing that he will learn if you write the code for him is copy & paste.
Kaj
kajbja at 2007-7-21 11:03:01 >

> > I must also add that the previous code only works
> for
> > odd length plaindromes.
> >
> > Use this method and it'll work for even and odd
> ones.
> > Sorry I forgot about that...silly me.
>
> Why not change it to..
> > public static boolean isPalindrome(String text) {
> return text.equals(new
> ew StringBuilder(text).reverse().toString());
> }
>
>
> Kaj
There's more than one way to skin a cat.
> > >
> > > Do you think you are helping?
> >
> > I sure do. Hey, I don't know swing at all. She
> > still has to do that part.
>
> How much do you think the OP is learning if he
> doesn't give it a try on his own? The only thing that
> he will learn if you write the code for him is copy &
> paste.
>
> Kaj
I don't care what they learn. That's up to them. I'm not the learning police.
> > >
> > > Do you think you are helping?
> >
> > I sure do. Hey, I don't know swing at all. She
> > still has to do that part.
>
> How much do you think the OP is learning if he
> doesn't give it a try on his own? The only thing that
> he will learn if you write the code for him is copy &
> paste.
>
> Kaj
Kaj,
There is some backstory you are missing here. I suggest reading the following thread
http://forum.java.sun.com/thread.jspa?threadID=769644
> There's more than one way to skin a cat.But not all of them are good. Your code is hard to follow and maintain.
kajbja at 2007-7-21 11:03:01 >

> > > >
> > > > Do you think you are helping?
> > >
> > > I sure do. Hey, I don't know swing at all. She
> > > still has to do that part.
> >
> > How much do you think the OP is learning if he
> > doesn't give it a try on his own? The only thing
> that
> > he will learn if you write the code for him is copy
> &
> > paste.
> >
> > Kaj
>
> I don't care what they learn. That's up to them.
> I'm not the learning police.
This is true. You have planted yourself firmly with the Ulrika gestapo.
> > There's more than one way to skin a cat.> > But not all of them are good. Your code is hard to> follow and maintain.He doesn't care.
> I don't care what they learn. That's up to them.> I'm not the learning police.This sounds very similar to "I post here to amuse myself".
> Why not change it to..
> > public static boolean isPalindrome(String text) {
> return text.equals(new
> ew StringBuilder(text).reverse().toString());
> }
>
>
> Kaj
My way is also 3-4 times faster ;-)
> There is some backstory you are missing here. I> suggest reading the following thread> > http://forum.java.sun.com/thread.jspa?threadID=769644Thanks. But why is he posting crappy code if he wants to help?
kajbja at 2007-7-21 11:03:01 >

And neither code fulfills the GUI requirement. :)
> > There's more than one way to skin a cat.> > But not all of them are good. Your code is hard to> follow and maintain.OK, how about this. My way is a good bit faster than yours.....:rolleyes:
> > There is some backstory you are missing here. I
> > suggest reading the following thread
> >
> >
> http://forum.java.sun.com/thread.jspa?threadID=769644
>
> Thanks. But why is he posting crappy code if he wants
> to help?
I think because
a) he doesn't know any better
b) he doesn't care because the OP failing is his goal in the end
So help is sort of a subjective term in this instance.
> And neither code fulfills the GUI requirement. :)I never said it did. I'm not about to write and swing code. Not my thing.
> Thanks. But why is he posting crappy code if he wants
> to help?
Did I mention that he's just holding a grudge and wants to try all he can to tick me off?
He's not interested in helping people. He's relegated himself to the position of homework slave to see if he can tick me off. It's fun to watch, kind of.
> OK, how about this. My way is a good bit faster than> yours.....:rolleyes:Why write code which is hard to follow before you know that the performance is a problem?
kajbja at 2007-7-21 11:03:06 >

> Thanks. But why is he posting crappy code if he wants to help?
It's not crappy, it's geeky I'd say. It is more efficient, but it looks like it's from someone with a background in C++. :)
I don't like homework being solved that way here - it helps neither us nor them (in fact, it'll keep traffic high, since there's more than one assignment) - but the code itself is good. Could be much worse.
NO, it's not just to tick you off. I was doing it before you went crazy. Maybe it's to take away a little bit of the power trip some of you guys have when total noobs post.
I agree what I'm doing is probably not going ot be helpful to anyone, but it's better than reading the same drivel from the same people over and over again.
> I agree what I'm doing is probably not going ot be> helpful to anyone, but it's better than reading the> same drivel from the same people over and over again.We love you too sweetheart.
> > Thanks. But why is he posting crappy code if he
> wants to help?
>
> It's not crappy, it's geeky I'd say. It is more
> efficient, but it looks like it's from someone with a
> background in C++. :)
>
> I don't like homework being solved that way here - it
> helps neither us nor them (in fact, it'll keep
> traffic high, since there's more than one assignment)
> - but the code itself is good. Could be much worse.
Well thank you for at least being honest :-D
> Maybe it's to take away a
> little bit of the power trip some of you guys have
> when total noobs post.
LOL
> I agree what I'm doing is probably not going ot be
> helpful to anyone, but it's better than reading the
> same drivel from the same people over and over again.
better in what sense?
If someone wants readymade solutions, they should be rightly directed to http://www.geekinterview.com/
>if ( PALINDROME_LENGTH % 2 == 1 )
>{
> halfLength = (PALINDROME_LENGTH - 1) / 2;
> }
> else
> {
> halfLength = PALINDROME_LENGTH / 2;
I don't see how that is any different from this:halfLength= PALINDROME_LENGTH/2;
I find the first version so verbose and confusing. btw, as Kaj already
had shown: there are better, more concise ways to figure out if
something is a palindrome or not. Please don't post home brew
solutions, especially not when they are wobbly and also especially not
when the OP can't learn anything from it. You are not doing the new
folks around a favour.
kind regards,
Jos
JosAHa at 2007-7-21 11:03:06 >

> If someone wants readymade solutions, they should be> rightly directed to http://www.geekinterview.com/Well apparantly that's not true anymore, now that we have a homework slave among us.Dance, Jerkweed, dance!
> >if ( PALINDROME_LENGTH % 2 == 1 )
> >{
> > halfLength = (PALINDROME_LENGTH - 1) / 2;
> > }
> > else
> > {
> > halfLength = PALINDROME_LENGTH /
> 2;
> I don't see how that is any different from
> this:> halfLength= PALINDROME_LENGTH/2;
>
> I find the first version so verbose and confusing.
> btw, as Kaj already
> had shown: there are better, more concise ways to
> figure out if
> something is a palindrome or not. Please don't post
> home brew
> solutions, especially not when they are wobbly and
> also especially not
> when the OP can't learn anything from it. You are not
> doing the new
> folks around a favour.
>
> kind regards,
>
> Jos
Yup x/2 works a lot better. I like all the code analysis, pick it appart all you like, fine with me. I wrote it fast and am bound to make some mistakes. Yu realize by correxting my code you're actually helping the OP any more.
It seems a bit ironic to me. You don't want to do any homework, so I do it, you hate it so I keep doing it, you hate that I do it and thus correct my code trying to make me feel stupid in the hopes that I'll go away, however, in the end you're acutally just helping the OP get better code.
Good work guys.
> > Thanks. But why is he posting crappy code if he
> wants to help?
>
> It's not crappy, it's geeky I'd say. It is more
> efficient, but it looks like it's from someone with a
> background in C++. :)
Hush. I'm trying to poke him with a stick. I want to see him upset :)
kajbja at 2007-7-21 11:03:06 >

> I agree what I'm doing is probably not going ot be
> helpful to anyone, but it's better than reading the
> same drivel from the same people over and over again.
Oh, yes, totally. I can't believe the drivel that people post. **** like, "Try to do it yourself, then post what you've got and ask specific questions about the suff that's giving you trouble." What a bunch of malarkey! How dare we keep repeating that same old nonsense to these poor beleagured posters!
jverda at 2007-7-21 11:03:06 >

> It seems a bit ironic to me. You don't want to do> any homework, so I do it, you hate it so I keep doing> it, you hate that I do it and thus correct my codeThe difference is that the code which I posted probably won't be accepted by his professor.
kajbja at 2007-7-21 11:03:07 >

> > I agree what I'm doing is probably not going ot be
> > helpful to anyone, but it's better than reading
> the
> > same drivel from the same people over and over
> again.
>
> Oh, yes, totally. I can't believe the drivel that
> people post. **** like, "Try to do it yourself,
> then post what you've got and ask specific questions
> about the suff that's giving you trouble." What a
> bunch of malarkey! How dare we keep repeating that
> same old nonsense to these poor beleagured posters!
Good morning Jeff. :)
> > It seems a bit ironic to me. You don't want to do
> > any homework, so I do it, you hate it so I keep
> doing
> > it, you hate that I do it and thus correct my code
>
> The difference is that the code which I posted
> probably won't be accepted by his professor.
I don't see why it wouldn't be?
> > The difference is that the code which I posted
> > probably won't be accepted by his professor.
>
> I don't see why it wouldn't be?
1) The professor will probably notice that it isn't written by a beginner.
2) The professor probably wants the OP to use a loop, so he will tell him to do it using a loop instead.
Kaj
kajbja at 2007-7-21 11:03:11 >

> It seems a bit ironic to me. You don't want to do
> any homework, so I do it, you hate it so I keep doing
> it, you hate that I do it and thus correct my code
> trying to make me feel stupid in the hopes that I'll
> go away, however, in the end you're acutally just
> helping the OP get better code.
Your mind works in a very funny way.
Jos
JosAHa at 2007-7-21 11:03:12 >

> It seems a bit ironic to me. You don't want to do
> any homework, so I do it, you hate it so I keep doing
> it, you hate that I do it and thus correct my code
> trying to make me feel stupid in the hopes that I'll
> go away, however, in the end you're acutally just
> helping the OP get better code.
It would be even ironic when the OP copies the first posted code and gets satisfied and ignores all the refinements. :)
> thanks a lot... :D*snort*
> Your mind works in a very funny way.> > JosSure does.