Palindrome java help

Need help debugin code

Page 1 of 1

5 Replies - 803 Views - Last Post: 29 September 2009 - 06:54 AM Rate Topic: -----

#1 cashflo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 29-September 09

Palindrome java help

Posted 29 September 2009 - 03:16 AM

Im running out of time to figure were I got this wrong

I get the following error
cannot find symbol
symbol : class Palindrome
location: class test.Palindrome_main
Palindrome result = new Palindrome(input);

package test;

import java.util.Scanner;

public class Palindrome_main
{
   public static void main(String[] args)
   { 
	  String input = "";
	  String str = "";
	  Scanner scan = new Scanner(System.in);
	  System.out.print("Enter a string: ");
		 while(true)
	  {

		 str = scan.nextLine();
		 if(str.length() == 0)
		 break;
		 if(str.length() > 1)
		 {
			System.out.println("Only one character");
		  str= scan.nextLine();
		 }

	  input+= str;
	  }

	 Palindrome result = new Palindrome(input);
	 if(result.isPalindrome())
	   System.out.println("This is a Palindrome string");
	 else
	   System.out.println("This is not a Palindrome string"); 
   } 
}


package test;
import java.util.Stack;
public class Palindrome {
	  private String input;
	  private Stack<Character> charStack = new Stack<Character>();
	 
	  public Palindrome (String input) 
	  {
		  this.input = input;
		  fillStack();
	  }
  
	  private void fillStack () 
	  {
		  for (int i = 0, len = input.length();i < len;++i) 
		  {
			charStack.push(input.charAt(i));
		  }
	  }

	  private String buildReverse() 
	  {
		  StringBuilder result = new StringBuilder();
		  while (!charStack.empty()) 
		  {
			result.append(charStack.pop());
		  }
		  return result.toString();
	  }
	  
	  public boolean isPalindrome () 
	  {	 
		  return input.equalsIgnoreCase(buildReverse());
	  }  
	 
	} 


Is This A Good Question/Topic? 0
  • +

Replies To: Palindrome java help

#2 rishabhsharma  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 10
  • View blog
  • Posts: 342
  • Joined: 26-March 09

Re: Palindrome java help

Posted 29 September 2009 - 03:24 AM

Your program in running fine............what's the problem.......
Was This Post Helpful? 0
  • +
  • -

#3 greenDevil  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 15
  • Joined: 14-September 09

Re: Palindrome java help

Posted 29 September 2009 - 03:30 AM

It woks fine I've tried it.

try to compile the Palindrome class before the Palindrome_main. Just a thought.
Was This Post Helpful? 0
  • +
  • -

#4 cashflo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 29-September 09

Re: Palindrome java help

Posted 29 September 2009 - 06:09 AM

View PostgreenDevil, on 29 Sep, 2009 - 02:30 AM, said:

It woks fine I've tried it.

try to compile the Palindrome class before the Palindrome_main. Just a thought.

still getting these errors

-Called Compiler C:\PROGRA~1\Java\JDK15~1.0_0\bin\javac.exe-
-Target File: C:\DOCUME~1\adm\MYDOCU~1\CSIS22~1\CH17\Palindrome_main.java-
C:\DOCUME~1\adm\MYDOCU~1\CSIS22~1\CH17\Palindrome_main.java:28: cannot find symbol
symbol : class Palindrome
location: class test.Palindrome_main
Palindrome result = new Palindrome(input);
^
C:\DOCUME~1\adm\MYDOCU~1\CSIS22~1\CH17\Palindrome_main.java:28: cannot find symbol
symbol : class Palindrome
location: class test.Palindrome_main
Palindrome result = new Palindrome(input);
^
2 errors

-Finished-
Was This Post Helpful? 0
  • +
  • -

#5 greenDevil  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 15
  • Joined: 14-September 09

Re: Palindrome java help

Posted 29 September 2009 - 06:35 AM

You probably haven't created package test
try deleting the first line in both files. I can guarantee it's going to work.
Read more about packages in
http://java.sun.com/...kage/index.html
Was This Post Helpful? 1
  • +
  • -

#6 cashflo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 29-September 09

Re: Palindrome java help

Posted 29 September 2009 - 06:54 AM

That was it. That was it. This class is online and I usually try to copy example in book and alter to meet the exercise requirements.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1