I recommend you use the -Xlint option with the javac command to get better compiler error messages:
D:\Java\jdk1.7.0.7\bin\javac.exe -cp . -Xlint TestCode15.java

One problem I see is the quote char surrounding a String are not both: ". Your keyboard must have different chars for starting and ending "s.

10-16-2013, 02:38 AM

Jamiemcg

Re: Need Urgent Help with my Java Program import.java.util.Scanner; public class T

Hello, M.ubc!

The reason that you're getting the "identifier expected" error on the first line when trying to compile your code is because there is a period between import and java (which is the beginning of the package and class that you're going to import).

If you remove the period so that the line reads import java.util.Scanner;, that error will disappear.

Regarding the other errors that are preventing you from compiling your program, there were semicolons included after the conditions of some of the if statements in your program, before the opening curly brace, which may have been causing some of the errors that you were receiving.

Additionally, I would recommend that you post your code using code tags, so that it is displayed with proper syntax highlighting and formatting.

I pasted your code into Dr. Java and edited it, (I had to change your quotation marks, since they were causing errors when I tried to compile, though I think that may be a minor issue and will probably not affect your code if you were able to compile without errors related to it previously) removing unnecessary semicolons and trying to format things appropriately.

I also added a few curly braces, if I thought they may have been needed, though I could be mistaken due to it not being formatted properly when I copied and pasted it into Dr. Java.

While this code still didn't compile, hopefully some of the compiler errors that you were receiving are now gone.

Best of luck and I hope I helped you!

- Jamie

10-16-2013, 02:56 AM

M.ubc

Re: Need Urgent Help with my Java Program import.java.util.Scanner; public class T

Oh ok thanks guys. I tried your part Jamie and it did not work in getting rid of the else if errors, but also added more errors when i took out the semi colons, i was down to 3 errors and now at 12, all the added errors were missing semi colons, so im confused as to how what happened. Also i have no idea why the else without if keeps showing up.

Re: Need Urgent Help with my Java Program import.java.util.Scanner; public class T

The code needs formatting. Nested statements should be indented 3-4 spaces to show the logic. The statements should not all start in the first column.

Also you need to copy the full text of the error messages and paste it here.

10-16-2013, 03:46 AM

kjkrum

Re: Need Urgent Help with my Java Program import.java.util.Scanner; public class T

Don't capitalize keywords. Their case is part of their spelling.

10-16-2013, 03:50 AM

Jamiemcg

Re: Need Urgent Help with my Java Program import.java.util.Scanner; public class T

Like Norm suggested, you should take a few minutes to go through your code and format it to show how the while loop and conditional statements are supposed to be nested, which would aid other members in helping you figure out what is causing the errors.

Additionally, when nesting conditional statements, like if/else if/ else statements, you may want to use curly brackets and indentation to indicate which statements are nested within other statements, which will make the code more organized and easier to read.

When using curly brackets, it is a good idea to ensure that every opening bracket has a closing bracket, and that you are consistent throughout your program. (You may want to include curly brackets, even if the conditional statement does not require them, so that it is consistent the rest of your code.)

As for the semicolon issues, a semicolon is used to end a statement or method, and should not be used after a conditional statement, like an if statement, as seen in line 38 of the code you posted, which is If( dblez ==yes);. Removing the semicolon here (and after other conditional statements) will probably get rid of some of the errors that you are receiving when trying to compile your code.

Another thing to note, also on line 38, is that if you're comparing the content of Strings, you should use the .equals() method, as using the "equality" operator (==) will check whether or not two Strings are in the same location in memory and not whether or not they are the same. (I actually made this error in my first reply to this thread, by wrapping quotation marks around "yes", and not using the .equals() method! My apologies for that!)

So, instead of having:

Code:

If( dblez ==yes){
//code here
}

or

Code:

If( dblez == "yes"){
//code here
}

You should have:

Code:

If( dblez.equals("yes") ){
//code here
}

Best of luck and I hope I helped you!

- Jamie

10-16-2013, 09:31 PM

M.ubc

Re: Need Urgent Help with my Java Program import.java.util.Scanner; public class T

The program compiles now. It just stops at an infinite loop at the "I suck at programming" test string
It asks what is speed limit, asks what are priors, then asks simultaneously if its doublezone and enter speed of vehicle? Then goes on infinite loop. Im not sure how to debug it.