code compiling problem

I have written a small sample code with 2 classes(Money.java and MoreMoney.java),where the latter has the main function. The problem is i cant compile and run these programs using commmand prompt in windows but they work just fine when using netbeans.

Env. variable is not a problem as money.java compiles using command prompt. Importing is not an issue as they are in the same package. Nor is package an issue, coz i have written the package name at the start of the code. Please suggest.Thank you in advance.

The code is as follows:

/*

* Money.java

*

* Created on August 8, 2006, 11:09 AM

*

* To change this template, choose Tools | Template Manager

* and open the template in the editor.

*/

package javaapplication1;

/**

*

* @author oracle

*/

public class Money

{

private float amount;

private int dollars;

private float cents;

public Money(int amount)

{

dollars=amount/100;

cents=amount%100;

}

public float getdollar()

{

return this.dollars;

}

public float getcents()

{

return this.cents;

}

public String toString()

{

return("You Entered "+dollars+" dollars and "+cents+" cents");

}

}

/*

* MoreMoney.java

*

* Created on August 1, 2006, 5:36 PM

*

* To change this template, choose Tools | Template Manager

* and open the template in the editor.

*/

package javaapplication1;

/**

*

* @author oracle

*/

public class MoreMoney

{

/**

* @param args the command line arguments

*/

public static void main(String[] args)

{

// TODO code application logic here

Money m=new Money(143);

System.out.println(m);

}

}

Any other tips on my code are also welcome since i am new to java and would like to learn good 'coding habits'.

[2037 byte] By [Bionerda] at [2007-10-3 2:13:50]
# 1
Please use the code tags and also post the error message you are getting.
zadoka at 2007-7-14 19:12:40 > top of Java-index,Java Essentials,New To Java...
# 2

I am not sure what are code tags.

But here are the 2 errors (shown by ^ under the word 'Money')

MoreMoney.java:24: cannot find symbol

symbol: class Money

location: class javaapplication1.Moremoney

Money m = new Money();

MoreMoney.java:24: cannot find symbol

symbol: class Money

location: class javaapplication1.Moremoney

Money m = new Money();

bionerda at 2007-7-14 19:12:40 > top of Java-index,Java Essentials,New To Java...
# 3
> I am not sure what are code tags. > [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags[/url]
zadoka at 2007-7-14 19:12:40 > top of Java-index,Java Essentials,New To Java...
# 4
What are you typing a the command line to complie these?
zadoka at 2007-7-14 19:12:40 > top of Java-index,Java Essentials,New To Java...
# 5

Here is what i did in the command line prompt.

C:\Program Files\Java\jdk 1.5.0_07\bin\JavaApplication1\src\JavaApplication1> javac Money.java

// This compiled w/o errors.

C:\Program Files\Java\jdk 1.5.0_07\bin\JavaApplication1\src\JavaApplication1> javac MoreMoney.java

// After i do this, i get those errors i metioned in my earlier message. I am sorry, I am new to java (and programming itself), so could not understand the 'code tags'. I hope i got it right this time.

bionerda at 2007-7-14 19:12:40 > top of Java-index,Java Essentials,New To Java...
# 6

This problem should be solved by setting the CLASSPATH environment variable [adding the folder containing .class file] , or by moving all of .class file to the same directory of src code[where you're compiling MoreMoney.java] and removing the line [authomatically generated by Netbeans]

package javaapplication1;

one of this should work, if I'm not wrong.

JoYiCk

Message was edited by:

JoYsTiCk

JoYsTiCka at 2007-7-14 19:12:40 > top of Java-index,Java Essentials,New To Java...
# 7

Hello,

Thank you for the suggestion.

I already have my .class files & my .java files in the JavaApplication1 folder. I have done as instructed on the webpage (http://java.sun.com/javase/6/webnotes/install/jdk/install-windows.html#Environment) and also have set the environment variable, CLASSPATH to the value:

C:\Program Files\Java\jdk 1.5.0_07\bin\JavaApplication1\src\ JavaApplication1

When i say env. varible it is the 'systems variable' of the env. variable category. Am i correct on that one?

I have another piece of information. After setting the CLASSPATH to its new value and restarting command prompt, it did not automatically go to that directory/path. It instead gave me the default path(C:/Documetns and Settings/oracle>)

I had to manually change the directory until i had the above mentioned path. Is there something fishy about my DOS-prompt or is that the way it is supposed to be?

So inspite all this experimentation the problem still persists. Why wont my code compile from DOS-Prompt? Thank you for your patience and please advice.

bionerda at 2007-7-14 19:12:40 > top of Java-index,Java Essentials,New To Java...
# 8

>I had to manually change the directory until i had the >above mentioned path. Is >there something fishy about >my DOS-prompt or is that the way it is supposed >to be?

It's how it is supposed to be.

Are you sure you commented/removed the line

package javaapplication1;

?

If you do so, you should be able to compile it, if the other needed .class file is in the same directory or in any directory in CLASSPATH.

If this doesn't work either, I really don't know how to help you.

JoYiCk

edit after some trials:

try to remove the package line even from Money.java and recompile it. Then remove the same line even from MoreMoney.java and recompile.

If you instead prefer or need using package, I'm afraid I can't help you, I'm not very good at using packages :-(

JoYiCk

Message was edited by:

JoYsTiCk

JoYsTiCka at 2007-7-14 19:12:40 > top of Java-index,Java Essentials,New To Java...