Java: Classes do not find each other in package (factory design pattern) -
i have 3 different classes:
woman.java
package human; public class woman extends human{ private final string pnr; private final string namn; public woman(string n, string p){ namn = n; pnr = p; } public string tostring(){ return "my name "+namn+" , woman."; } }
man.java
package human; public class man extends human{ private final string pnr; private final string namn; public man(string n, string p){ namn = n; pnr = p; } public string tostring(){ return "my name "+namn+" , man."; } }
human.java
package human; public abstract class human{ public static human create(string namn, string pnr){ char nastsist_char = pnr.charat(9); // takes second last char in pnr string nastsist_string = character.tostring(nastsist_char); float siffra = float.parsefloat(nastsist_string); //converts float if ((siffra % 2) == 0){ //checks if return new man(namn, pnr); } else{ return new woman(namn, pnr); } } }
when try compile file human.java, error
cannot find symbol: class man,
and
cannot find symbol: class woman.
when try compile file man.java or woman.java, error
cannot find symbol: class human.
no changing of public/private
visibility of classes have helped. files located in directory called human
.
what problem here?
i should add goal i'm trying achieve have abstract class human can not instantiated, , in class want have create method returns instances of either man or woman depending on pnr
. also, not want man or woman possible instantiate in other way through create method.
thanks
there's no problem code or packaging, problem elsewhere. how compile? i'm guessing might doing
javac human/human.java
which not work, since man
, woman
not on classpath , not known java compiler when working on human
. should include these when compiling:
javac human/*.java
cheers,
Comments
Post a Comment