File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java

 
rashid brown
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi im new to Java and every time i enter javac (file name) in cmd it comes up as a error this is the first time I put a set of codes together could anyone tell me if there a error in this code or is it just my PC as I have heard some people say.

public class CarRally {

a = JOptionPane.showInputDialog
(null, "Enter Name");
a = JOptionPane.showInputDialog

String a;
a = JOptionPane.showInputDialog
(null, "Enter M for male or F for female?");
while (!(a.equalsIgnoreCase("M")||a.equalsIgnoreCase("F")){
a = JOptionPane.showInputDialog
(null, "You must enter M or F?");
}

String a;
a = JOptionPane.showInputDialog
(null, "Enter Starting Hour (0 to 23)");
int hour = integer.parseInt (a);
while (hour < 0 || hour > 23){
a = JOptionPane.ShowInputDialog
(null, "Hour wrong, please try again");
Hour = integer.parseInt (a);
}// end while

String a;
a = JOptionPane.showInputDialog
(null, "Enter Starting Minutes (0 to 60)");
int minutes = integer.parseInt (a);
while (minutes < 0 || minutes > 60){
a = JOptionPane.ShowInputDialog
(null, "Minutes wrong, please try again");
minutes = integer.parseInt (a);
}// end while

String a;
a = JOptionPane.showInputDialog
(null, "Enter Starting Seconds (0 to 60)");
int seconds = integer.parseInt (a);
while (seconds < 0 || seconds > 60){
a = JOptionPane.ShowInputDialog
(null, "Seconds wrong, please try again");
seconds = integer.parseInt (a);
}// end while

String a;
a = JOptionPane.showInputDialog
(null, "Enter end Hour (0 to 23)");
int hour = integer.parseInt (a);
while (hour < 0 || hour > 23){
a = JOptionPane.ShowInputDialog
(null, "Hour wrong, please try again");
Hour = integer.parseInt (a);
}// end while

String a;
a = JOptionPane.showInputDialog
(null, "Enter end Minutes (0 to 60)");
int minutes = integer.parseInt (a);
while (minutes < 0 || minutes > 60){
a = JOptionPane.ShowInputDialog
(null, "Minutes wrong, please try again");
minutes = integer.parseInt (a);
}// end while

String a;
a = JOptionPane.showInputDialog
(null, "Enter end Seconds (0 to 60)");
int seconds = integer.parseInt (a);
while (seconds < 0 || seconds > 60){
a = JOptionPane.ShowInputDialog
(null, "Seconds wrong, please try again");
seconds = integer.parseInt (a);
}// end while

}// end of class
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rashid swaggerstar wrote:Hi im new to Java and every time i enter javac (file name) in cmd it comes up as a error this is the first time I put a set of codes together could anyone tell me if there a error in this code or is it just my PC as I have heard some people say.




Well, you definitely have tons of errors in your code... so, I agree with your compiler. I recommend that you look at the compiler errors, fix the first few, and then compile again. Don't fix them out of order -- fix the first one first. And don't do anymore than a few. The reason? There are so many weird syntax errors (such as code not in a constructor, method, or initializer), that I am sure that the compiler is completely confused after the first few.

Henry
 
rashid brown
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank but you have confused me more I have checked little errors and still keep saying 1error what ever I do
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rashid swaggerstar wrote:Thank but you have confused me more I have checked little errors and still keep saying 1error what ever I do


Care to share what this one error is?

Henry
 
rashid brown
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is what it previews when i enter javac CarRally
Picture1.jpg
[Thumbnail for Picture1.jpg]
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And note that you need to give your .java file name to the compiler.


 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote:And note that you need to give your .java file name to the compiler.




Agreed. The code needs to be in a file with a java extension. And you need to specify the filename to the compiler.

Henry
 
rashid brown
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have written like that wen saving it I have selected java file to save it and it says .java will I need to input that in to cmd
 
rashid brown
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have found out when that when I entered javac CarryRallu by accident instead of CarRally it came up with the same error messege
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rashid brown wrote:I have found out when that when I entered javac CarryRallu by accident instead of CarRally it came up with the same error messege


As already mentioned, you need to specify the name of the source file -- and that includes the ".java" extension.

Henry
 
rashid brown
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have tried javac CarRally.Java

and it says

javac: file not found: CarRally.java
Usage: javac <options><source files>
use -help for a list of possible options
 
rashid brown
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help I figured it out now came up with allot of error need to fix them now
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rashid brown wrote:i have tried javac CarRally.Java

and it says

javac: file not found: CarRally.java
Usage: javac <options><source files>
use -help for a list of possible options


As already mentioned, your CarRally class needs to be defined in a file named CarRally.java. The error is saying that the file does not exist. Do you have the class named in such as file?

Henry
 
rashid brown
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a qeustion if an error has a > pointing upwords toward your code what does that mean
 
Winston Gutkowski
Bartender
Pie
Posts: 9490
50
Eclipse IDE Hibernate Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rashid brown wrote:I have a qeustion if an error has a > pointing upwords toward your code what does that mean

It indicates, as closely as possible, the place that the compiler discovered the error.

Winston
 
rashid brown
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks could you check my code and tell me on the third line were the error is as it confusing me
 
rashid brown
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
because I have tried a=JOptionPane and a = JoptionPane and the error is by the = which is confusing
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rashid brown wrote:Thanks could you check my code and tell me on the third line were the error is as it confusing me


Generally, it would help if you do the heavy lifting -- meaning you show use the third line and show us the exact error code.... And hint... as already mentioned, you have lots of code in invalid locations. Code needs to be in a constructor, initializer, or method.

Henry
 
rashid brown
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as this is new to me I dont know were all the code is ment to go which is confusing me at the moment
 
rashid brown
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
every time i try change something i came up with more error then I started with
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rashid brown wrote:as this is new to me I dont know were all the code is ment to go which is confusing me at the moment
every time i try change something i came up with more error then I started with


Then maybe you are trying too hard and too much at the same time. Start with smaller programs, always compile a line of code and make sure it runs fine before writing another statement. If you write code in such bulk, you are bound to get confused as to where the error /exception is. Anyways, can you share the line that is causing the error?
 
rashid brown
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
better I will give that a try thank you
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rashid brown wrote:as this is new to me I dont know were all the code is ment to go which is confusing me at the moment


Yeah. It would be a good idea to understand where code is legal -- and the legal syntax of code. Coding by trial and error is not really productive.


rashid brown wrote:every time i try change something i came up with more error then I started with


Interestingly, you can't really tell. These type of errors tend to confuse the compiler to the point that only the first few errors are correct. Also, you can probably get rid of most of these errors by throwing everything into a main() method... but ... That is not the point. Getting rid of compiler errors doesn't mean that you fixed everything.

Henry

 
rashid brown
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have started again and i have the last bit of code left but when insertint gender I have allowed the user inputing to select this is and the output to show with his name but there is no space how to i create a space in the output
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12022
25
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Surely by now, you must realize we are not mind readers. We do not have ANY idea what your code does, what it is supposed to do, why it doesn't work, or what advice to give you - because we have NO IDEA what your code looks like.

There are hundreds of different ways you could be showing a name, and for each of those, a hundred different ways it could be wrong.

I strongly suggest you read our FAQ and take to heart the advice given there.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic