This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Recursion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Recursion" Watch "Recursion" New topic
Author

Recursion

Corbin Blake
Greenhorn

Joined: Nov 10, 2004
Posts: 22
We are studying recursion and I am trying to write method that tests the contents of an array for a palindrome. I keep getting a charAt method undefined. I don't know why it is undefined thought!?!



I have tried to find information in books and online on how to use this method, to test the contents of an array. I have not found it yet. Maybe you guys can help me.
Elouise Kivineva
Ranch Hand

Joined: Feb 07, 2002
Posts: 154
Is your variable named "sequence" a string?
Corbin Blake
Greenhorn

Joined: Nov 10, 2004
Posts: 22
sequence is a string,yes. I was just trying to get this to work using the string. My real goal is to get it working with an array, seqArray, which is holding the collection of information.
Corbin Blake
Greenhorn

Joined: Nov 10, 2004
Posts: 22
I am using getChar method that is part of the array class, and i am getting an error there. It looks like this.

char first = Character.getChar(seqArray[0].sequence); // error here.

I am trying everything that i can think of.
Elouise Kivineva
Ranch Hand

Joined: Feb 07, 2002
Posts: 154
If you want to use an Array object you need to import the java.lang.reflect.Array class.

Why all this fancy stuff? Wouldn't an array work just as well?
Corbin Blake
Greenhorn

Joined: Nov 10, 2004
Posts: 22
my professor wants us to use recursion
Elouise Kivineva
Ranch Hand

Joined: Feb 07, 2002
Posts: 154
You want to compare the first and last chars in a string of length 2 or more and the string being evaluated is a smaller and smaller bit centered around the middle of the original string.

I would create a method that takes a string as a parameter and returns a boolean. Don't need anything more than String-class methods.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Originally posted by Elouise Kivineva:
If you want to use an Array object you need to import the java.lang.reflect.Array class.


Note that the class you've mentioned is for advanced applications and has nothing whatsoever to do with the problem at hand.


[Jess in Action][AskingGoodQuestions]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Corbin, I will try to help you if you would please show us either your complete program, or the actual error message from the compiler (cut and pasted, not paraphrased!) or both. But based on what you've shown here, I can't tell you why you're getting an error.
Corbin Blake
Greenhorn

Joined: Nov 10, 2004
Posts: 22
Okay, i will post the entire code. Give me a minute.
Corbin Blake
Greenhorn

Joined: Nov 10, 2004
Posts: 22
I am gogin to email the files to you there are a lot of them.
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
It would be helpful for you to post the code here. That way all of us can try to help you out, especially if Ernest isn't available at the moment. If you have a lot of code, you are probably making this more complicated than it should be. I would guess a palindrome verifier shouldn't be more than 100 lines of code (give or take).

With that said, you should still be able to post only the lines of code that are giving the compiler error along with the actual text of the error message (copy-and-pasted not paraphrased).

Anyway, I hope we can help you find your problem. As Ernest says, additional information will definitely help us help you.

Keep Coding!

Layne


Java API Documentation
The Java Tutorial
Corbin Blake
Greenhorn

Joined: Nov 10, 2004
Posts: 22
here is the code.



Any help would be greatly appreciated

[ edited to break long code line -ds ]
[ November 28, 2004: Message edited by: Dirk Schreckmann ]
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

One thing I see at a quick glance is that you have a local variable named "sequence" in your isPanlidrome() method that is hiding the sequence variable defined at the class level.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

Also, your error is accurate -- Tube takes a Sequence, not a String. a String is not a Sequence.
Corbin Blake
Greenhorn

Joined: Nov 10, 2004
Posts: 22
Okay, i've got that part figured out. I am now writing in the test file. Is there a way to pass an array into a String. Here is what my program does.

Welcome to my program!

Enter d to create a random tube, s to save the entered sequences to a file, o for test tube operations, x to exit:

d
Enter Number of Sequences:

4
Enter Length of Sequence:

10
Enter Concentration of Sequences:

2
ATGGTCCTCG
ATGGTCCTCG
ACGAAAGTCT
ACGAAAGTCT
GCACAAGAGT
GCACAAGAGT
CACCCATTTA
CACCCATTTA

Enter d to create a random tube, s to save the entered sequences to a file, o for test tube operations, x to exit:

o
Enter n to compute NCH DNA sequences, l to test ligase, p to test polymerase, or e to create an edge Sequence, r to find palindromes, and x to exit:

r
The palindromes are:
//The program resets itself right here...but i want it to list the palindromes in my array. please help!
Enter d to create a random tube, s to save the entered sequences to a file, o for test tube operations, x to exit:

here is my isPalindrome method:


My test method which is what i am having problems writing I am wondering how to take the sequences out of the array and parse them into a string.

Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
There is something not quite right between the error message and the line of code:



It looks like you are trying to create a new Sequence object and assign it to a Tube reference. Although this isn't at all what the error message is complaining about, it is definitely a problem. I think you need to do something more like:


The variable someSequence needs to be a valid instance of Sequence. I don't even know what Sequence is, so I don't know how you would create someSequence in the above line of code.

This program seems much more complicated than I expected. Are you only checking for palindromes or is there something more to this than that? Would you mind giving a link to the assignment description or at least pasting it here?

Thanks,

Layne
Corbin Blake
Greenhorn

Joined: Nov 10, 2004
Posts: 22
here is a link to the assignment
assignment 8
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Thanks. That should help us understand what you are trying to accomplish with this program.

I noticed a question that is hiding in one of your posts:

Is there a way to pass an array into a String?


However, I'm not exactly sure what you mean. Can you clarify?

You also say


I am wondering how to take the sequences out of the array and parse them into a string.


I probably haven't looked at your code closely enough. However, I do notice that you use the Sequence class a lot. I'm assuming this represents a gene sequence, but beyond that I don't know what Sequence is. Can you explain what you are trying to do here? I suspect this may be related to the first question I quoted...

Layne
[ November 23, 2004: Message edited by: Layne Lund ]
Corbin Blake
Greenhorn

Joined: Nov 10, 2004
Posts: 22
hey guys, i appologize for this but i read the assignment wrong. It was a lot easier once i have done what i am suppose to, but i am having one problem working with input from a file.

I have a file input, that i have to printout to the console, i did that no problem, but what i want to do now is check the contents of that file for palindromes. That's what the assignment is talking about.

Okay, here is my method for getting the input from the file.



i am trying to figure out how to work with the contents though? Do you use StringTokenizer? Here is what i have.
 
 
subject: Recursion
 
Similar Threads
palindrome program
palindrome not very proficient...
Palindrome
Palindrome
Palindrome no. problem