Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-29-2008, 10:01 PM
Member
 
Join Date: Jan 2008
Posts: 26
jvasilj1 is on a distinguished road
help student
can someone help me Im having trouble with my assingment, we have to debug two java programs and get them to be able to compile...they are still giving me errors. can somone help me see what im missing. here are the codes.

// Convert from Meters to Feet and Inches
The program should repeatedly input a length in meters
and then print that length in feet and inches.

private class MeterToFtIn
{
public static void main(String[ ] argv)
{
double meter, f, i;
int more;
Scanner console = new Scanner(System.in);

System.out.print("Do you wish to input another length in meters: ");
more = con.nextInt( );
more = more.toUpperCase( );
while(more.charAt(0) = 'Y')
{
System.out.print('Enter length in meters: ');
meter = con.nextDouble( );
f = meter * 3.28083989501312;
feet = (int) f;
inches = (int) (12 * (feet - f) + 0.5);

System.out.print("The length is ");
if (feet == 1)
System.out.print(feet + "foot ");
else
System.out.print(feet + "feet ");
if (inches == 1)
System.out.println(inches + " inch.");
else if (inches < 1)
System.out.println(inches + " inches.");
else
System.out.println(".");

System.out.print(
"Do you wish to input another length in meters: ");
more = con.next( );
more = more.toUpperCase;
}
}
}

--------------------------------------------------------
heres the second one


// Check to see if an input string is a palindrome

// orig is the original string,
// processed is the string after removing all characters
/ that are not letters and converting to upper case.

Public class PalindromeCheck
{
private static void main(String argv)
{
string orig, processed, letter;
int left, right;
Scanner con = new Scanner(System.out);

System.out.println("Enter a string:");
orig = con.next;
for(i = 0; i < orig.length( ); i++)
{
letter = orig.charAt(i);
if (Character.isLetter(letter))
processed += Character.toUpperCase( );
}

if (processed.length( ) < 0)
{
left = 0;
right = processed.length( );
while (left < right)
{
if (processed.charAt(left) != processed.charAt(right))
System.out.println("String is not a palindrome.");
else
System.out.println("String is a palindrome.");

left++;
right--;
}
System.out.println("String is a palindrome.");
}

}
}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-29-2008, 10:44 PM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 294
tim is on a distinguished road
Done first one
Hello jvasilj1

I fixed the first one for you:
Code:
import java.util.Scanner; // import Scanner // Convert from Meters to Feet and Inches The program should repeatedly input a length in meters and then print that length in feet and inches. public class MeterToFtIn { public static void main(String[ ] argv) { double meter, f, i; String more; // Should be a string Scanner con = new Scanner(System.in); //con is used in program, not "console" System.out.print("Do you wish to input another length in meters: "); more = con.nextLine( ); // Reading a String more = more.toUpperCase( ); while(more.charAt(0) == 'Y'){ // equals-equals is for comparing and equal is for assigning System.out.print("Enter length in meters: "); // double quotes here meter = con.nextDouble( ); double feet = meter * 3.28083989501312; f = (int) feet; int inches = (int) (12 * (feet - f) + 0.5); System.out.print("The length is "); if (feet == 1) System.out.print(feet + "foot "); else System.out.print(feet + "feet "); if (inches == 1) System.out.println(inches + " inch."); else if (inches < 1) System.out.println(inches + " inches."); else System.out.println("."); System.out.print("Do you wish to input another length in meters: "); more = con.next( ); more = more.toUpperCase(); // Brackets missing } } }
The first program should run now. Try to debug the second yourself. It is the best way of learning how to deal with the compiler error messages.

Good luck
__________________
If your ship has not come in yet then build a lighthouse.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-29-2008, 11:13 PM
Member
 
Join Date: Jan 2008
Posts: 26
jvasilj1 is on a distinguished road
thanks....im trying the second one and it keeps giving me this error
----------------------------------
C:\Documents and Settings\dpuser\My Documents\PalindromeCheck.java:5: class, interface, or enum expected
/ that are not letters and converting to upper case.
^
1 error

Tool completed with exit code 1
------------------------------------------------
any help
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-29-2008, 11:16 PM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 294
tim is on a distinguished road
Symbol
The compiler is trying to tell you that it is expecting a class, interface or enum, which is OP stuff. The "/" is a devision symbol, but you wanted to add a comment ("//comment here") there. So, change your code so that you have two forward slashes:
Code:
// that are not letters and converting to upper case.
__________________
If your ship has not come in yet then build a lighthouse.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-29-2008, 11:19 PM
Member
 
Join Date: Jan 2008
Posts: 26
jvasilj1 is on a distinguished road
ok found it... now its giving me this

C:\Documents and Settings\dpuser\My Documents\PalindromeCheck.java:9: class, interface, or enum expected
Public class PalindromeCheck
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 01-29-2008, 11:24 PM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 294
tim is on a distinguished road
Case
Java is case sensitive. It is looking for the access modifier, in your case "public". The problem is that you spelled it with a capital P. Change it to:
Code:
public class PalindromeCheck
__________________
If your ship has not come in yet then build a lighthouse.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 01-29-2008, 11:31 PM
Member
 
Join Date: Jan 2008
Posts: 26
jvasilj1 is on a distinguished road
lol...i just changed it...then i checked here and saw ur post...hey thanks a lot in helping a novice work his way out...now it jumped to 8 errors....but im starting to get the hang of it.
------------------------------------------------
C:\Documents and Settings\dpuser\My Documents\PalindromeCheck.java:11: cannot find symbol
symbol : class string
location: class PalindromeCheck
string orig, processed, letter;
^
C:\Documents and Settings\dpuser\My Documents\PalindromeCheck.java:13: cannot find symbol
symbol : class Scanner
location: class PalindromeCheck
Scanner con = new Scanner(System.out);
^
C:\Documents and Settings\dpuser\My Documents\PalindromeCheck.java:13: cannot find symbol
symbol : class Scanner
location: class PalindromeCheck
Scanner con = new Scanner(System.out);
^
C:\Documents and Settings\dpuser\My Documents\PalindromeCheck.java:17: cannot find symbol
symbol : variable i
location: class PalindromeCheck
for(i = 0; i < orig.length( ); i++)
^
C:\Documents and Settings\dpuser\My Documents\PalindromeCheck.java:17: cannot find symbol
symbol : variable i
location: class PalindromeCheck
for(i = 0; i < orig.length( ); i++)
^
C:\Documents and Settings\dpuser\My Documents\PalindromeCheck.java:17: cannot find symbol
symbol : variable i
location: class PalindromeCheck
for(i = 0; i < orig.length( ); i++)
^
C:\Documents and Settings\dpuser\My Documents\PalindromeCheck.java:19: cannot find symbol
symbol : variable i
location: class PalindromeCheck
letter = orig.charAt(i);
^
C:\Documents and Settings\dpuser\My Documents\PalindromeCheck.java:21: cannot find symbol
symbol : method toUpperCase()
location: class java.lang.Character
processed += Character.toUpperCase( );
^
8 errors

Tool completed with exit code 1
-----------------------------------------------
now the errors are after that line so i know everything before it is ok...i guess im learning something, but now i dont know what is wrong with line 11
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 01-29-2008, 11:34 PM
Member
 
Join Date: Jan 2008
Posts: 26
jvasilj1 is on a distinguished road
i put int before the string orig in line 11...was that the right move?
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 01-29-2008, 11:34 PM
Member
 
Join Date: Jan 2008
Posts: 26
jvasilj1 is on a distinguished road
its only giving me 6 erros now
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 01-29-2008, 11:39 PM
Member
 
Join Date: Jan 2008
Posts: 26
jvasilj1 is on a distinguished road
can u compare this code which is my current code to the second code from my orignal post and tell me if im on the right track to cracking this?
-----------------------------------------

// Check to see if an input string is a palindrome
// orig is the original string,
// processed is the string after removing all characters
// that are not letters and converting to upper case.

import java.util.Scanner;

public class PalindromeCheck
{
private static void main(String argv)
{
String orig, processed, letter;
int left, right;
Scanner con = new Scanner(System.in);

System.out.println("Enter a string:");
orig = con.next;
for(i = 0; i < orig.length( ); i++)
{
letter = orig.charAt(i);
if (Character.isLetter(letter))
processed += Character.toUpperCase( );
}

if (processed.length( ) < 0);
{
left = 0;
right = processed.length( );
while (left < right)
{
if (processed.charAt(left) != processed.charAt(right))
System.out.println("String is not a palindrome.");
else
System.out.println("String is a palindrome.");

left++;
right--;
}
System.out.println("String is a palindrome.");
}

}
}
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 01-29-2008, 11:43 PM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 294
tim is on a distinguished road
Line 11: Its a case problem again. "String" is a class and is spelled with a capital "S".
Change it to
Code:
String orig, processed, letter;
Line 13: The Scanner class is not a standard java tool. It must be imported. Add the code:
Code:
import java.util.Scanner;
before
Code:
public class PalindromeCheck
For loops: You need to add int:
Code:
for(int i = 0; i < orig.length( ); i++)
It's getting late on this side of the planet. About 11:41 pm. I'm logging of now.

Good luck jvasilj1.
__________________
If your ship has not come in yet then build a lighthouse.
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 01-29-2008, 11:51 PM
Member
 
Join Date: Jan 2008
Posts: 26
jvasilj1 is on a distinguished road
this is now my code and it is giving me 4 errors. the errors are
--------------------------------------------------------------
C:\Documents and Settings\dpuser\My Documents\PalindromeCheck.java:17: cannot find symbol
symbol : variable next
location: class java.util.Scanner
orig = con.next;
^
C:\Documents and Settings\dpuser\My Documents\PalindromeCheck.java:20: incompatible types
found : char
required: java.lang.String
letter = orig.charAt(i);
^
C:\Documents and Settings\dpuser\My Documents\PalindromeCheck.java:21: cannot find symbol
symbol : method isLetter(java.lang.String)
location: class java.lang.Character
if (Character.isLetter(letter))
^
C:\Documents and Settings\dpuser\My Documents\PalindromeCheck.java:22: cannot find symbol
symbol : method toUpperCase()
location: class java.lang.Character
processed += Character.toUpperCase( );
^
4 errors

Tool completed with exit code 1
---------------------------------------------

this is my code
-------------------------------------
// Check to see if an input string is a palindrome
// orig is the original string,
// processed is the string after removing all characters
// that are not letters and converting to upper case.

import java.util.Scanner;

public class PalindromeCheck
{
private static void main(String argv)
{
String orig, processed, letter;
int left, right;
Scanner con = new Scanner(System.in);

System.out.println("Enter a string:");
orig = con.next;
for(int i = 0; i < orig.length( ); i++)
{
letter = orig.charAt(i);
if (Character.isLetter(letter))
processed += Character.toUpperCase( );
}

if (processed.length( ) < 0);
{
left = 0;
right = processed.length( );
while (left < right)
{
if (processed.charAt(left) != processed.charAt(right))
System.out.println("String is not a palindrome.");
else
System.out.println("String is a palindrome.");

left++;
right--;
}
System.out.println("String is a palindrome.");
}

}
}
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 01-30-2008, 12:41 AM
gibsonrocker800's Avatar
Senior Member
 
Join Date: Nov 2007
Location: New York
Posts: 143
gibsonrocker800 is on a distinguished road
Send a message via AIM to gibsonrocker800
Quote:
Originally Posted by jvasilj1 View Post

this is my code
-------------------------------------
// Check to see if an input string is a palindrome
// orig is the original string,
// processed is the string after removing all characters
// that are not letters and converting to upper case.

import java.util.Scanner;

public class PalindromeCheck
{
private static void main(String argv)
{
String orig, processed, letter;
int left, right;
Scanner con = new Scanner(System.in);

System.out.println("Enter a string:");
orig = con.next;
for(int i = 0; i < orig.length( ); i++)
{
letter = orig.charAt(i);
if (Character.isLetter(letter))
processed += Character.toUpperCase( );
}

if (processed.length( ) < 0);
{
left = 0;
right = processed.length( );
while (left < right)
{
if (processed.charAt(left) != processed.charAt(right))
System.out.println("String is not a palindrome.");
else
System.out.println("String is a palindrome.");

left++;
right--;
}
System.out.println("String is a palindrome.");
}

}
}

First of all. the main method is public static void main(String[] args)

private static void does not exist. I saw a thread a while ago asking why the main method is public. I actually found the answer in a book. It is because the method needs to be accessed at runtime.

Second
letter should be a char, not a String.

Third
Code:
processed += Character.toUpperCase( );
the toUpperCase method needs a char as its parameters. So, we will pass letter to it.

Last
Code:
if (processed.charAt(left) != processed.charAt(right))
It should be right - 1, since we are dealing with indexes.

Here is the updated code:


Code:
import java.util.Scanner; public class PalindromeCheck { public static void main(String args[]) { String orig, processed; processed = ""; char letter; int left, right; Scanner con = new Scanner(System.in); System.out.println("Enter a string:"); orig = con.next(); // for(int i = 0; i < orig.length( ); i++) { letter = orig.charAt(i); if (Character.isLetter(letter)) processed += Character.toUpperCase(letter); } if (processed.length( ) < 0); { left = 0; right = processed.length( ); while (left < right) { if (processed.charAt(left) != processed.charAt(right-1)) System.out.println("String is not a palindrome."); else System.out.println("String is a palindrome."); left++; right--; } System.out.println("String is a palindrome."); } } }
__________________
//Haha javac, can't see me now, can ya?
Bookmark Post in Technorati
Reply With Quote
  #14 (permalink)  
Old 01-30-2008, 12:53 AM
Member
 
Join Date: Jan 2008
Posts: 26
jvasilj1 is on a distinguished road
thanks i owe you some of my awesome programming talent (once i learn more java)
Bookmark Post in Technorati
Reply With Quote
  #15 (permalink)  
Old 01-30-2008, 01:23 AM
gibsonrocker800's Avatar
Senior Member
 
Join Date: Nov 2007
Location: New York
Posts: 143
gibsonrocker800 is on a distinguished road
Send a message via AIM to gibsonrocker800
Haha. be patient. You've got alot to learn. I always tell people this, but, it is important to be able to understand compile-time errors.
__________________
//Haha javac, can't see me now, can ya?
Bookmark Post in Technorati
Reply With Quote
  #16 (permalink)  
Old 02-02-2008, 09:23 AM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 740
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
Ah.. I see folks have already beaten me to the punch. OP - please see your original thread and refrain from double posting in the future. Thank you.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on July 13, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Student Help mattwaab Java Applets 0 02-08-2008 06:31 PM
please help a student jvasilj1 New To Java 0 02-01-2008 02:11 AM


All times are GMT +3. The time now is 10:48 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org