You wrote me :
Everything works fine when package fruitpackage is specified on top
of
both java classes.
But I don't know if I can send homework done in this way.

I think that the goal is to use "package" and "import" statements.
So you can

1. the 2 classes are in the same package :
-->create both Food.java and FoddMain.java in the package
"foodpackage.fruitpackage" and save it in the folder "c:
\path_to_your_workspace\foodpackage\fruitpackage"
-->declare "package foodpackage.fruitpackage;" or "package
fruitpackage;" at the top of 2 files

2. the 2 classes are not in the same package : Food is in
"foodpackage.fruitpackage" and FoodMain is in "fruitpackage"
-->declare "package foodpackage.fruitpackage;" for Food, and "package
fruitpackage;" for FoodMain
-->after package's declaration at the top of the file "FoodMain.java",
use "import foodpackage.fruitpackage"
-->verify to have saved FoodMain.java in the folder "c:
\path_to_your_workspace\fruitpackage", and Food.java in the folder "c:
\path_to_your_workspace\foodpackage\fruitpackage"

3. for compiling, use "c:\foodpackage\fruitpackage>javac ..\..
\FoodMain.java Food.java

The ..\..\ is to go up to 2 parent directories, to access the
fruitpackage directory (we are at "c:\foodpackage\fruitpackage" where
Food.java is, but FoodMain.java is at "c:\fruitjava").

@+

On 28 fév, 13:43, belmars <[email protected]> wrote:
> Just to rectify/add something :
>
> You declared
>
> --> package fruitpackage;
>     public class FoodMain
>
> --> package foodpackage.fruitpackage;
>     public class Food
>
> So, you have FoodMain.class and FoodMain.java in the folder
> your_workspace\fruitpackage\ , and Food.class and Food.java in the
> folder your_workspace\foodpackage\fruitpackage. Apply it to what I
> said before.
> (I think command "c:\foodpackage\fruitpackage>javac Food.java ..
> \FoodMain.java" from within "c:\foodpackage\fruitpackage" folder will
> work).
>
> @+
>
> On 28 fév, 13:14, belmars <[email protected]> wrote:
>
> >   Hello.
>
> >   First, you have to keep somthing in mind : when working in your IDE,
> > and declare classes and packages, they are stored in your workspace
> > (the folder in which you choose as your "root" folder to store
> > projects : I'll call it your_workspace).
>
> >   Then, when you declare a new package, it creates a new "namespace"
> > for relatives files, and will store them in the folder your_workspace/
> > your_package_name/ (assuming that you're working in linux. if not,
> > replace / by \ in the folder's path).
> >   Thus, if you create a new class as Food.class or FoodMain.class (by
> > creating and compiling Food.java and FoodMain.java) in your package
> > (by declaring the "package" statement in their declaration), you have
> > to look them in the folder your_workspace/your_package_name.
>
> >   Now, looking for your problem, it seems that you haven't declared
> > any "package" statement in the FoodMain.java. But when compiling in
> > command line, you used the command "c:\foodpackage\fruitpackage>javac
> > Food.java FoodMain.java" which indicates that you are in the folder
> > relative to "fruitpackage" package  : FoodMain.java is not here, you
> > have to look it in the folder c:\foodpackage, or in the folder
> > your_workspace.
> >   For compiling, try this command : c:\foodpackage>FoodMain.java from
> > within "c:\foodpackage" folder, or "c:\foodpackage\fruitpackage>javac
> > Food.java ..\FoodMain.java" from within "c:\foodpackage\fruitpackage"
> > folder.
>
> >   @+
>
> > On 28 fév, 11:10, Rafał Laczek <[email protected]> wrote:
>
> > > Hello Friends,
>
> > > I have a problem to create file FoodMain.class
> > > I used all suitable proposed in lesson commands. For example using
> > > following one:
> > > c:\foodpackage\fruitpackage>javac Food.java FoodMain.java
> > > system created Food.class in fruitpackage but regarding FoodMain I
> > > receive communicate:
> > > FoodMain.java: cannot find
> > > symbol: class Food
> > > location: class fruitpackage.FoodMain
> > > Food appleFood = new Food();  //this is one of the objects.
>
> > > The tops of classes in java files are following:
> > > package fruitpackage;
> > > public class FoodMain
>
> > > package foodpackage.fruitpackage;
> > > public class Food
>
> > > The cod of classes is OK because project works in IDE.
>
> > > I enclose print-screen.
>
> > > I am a beginner in Java.
>
> > > Thank you very much for your help!
>
> > > Best regards,
> > > Rafał
>
> > > ----------------------------------------------------
> > > ATRAKCYJNE NIERUCHOMOŚCI W ZAKOPANEM !!!
> > > Apartamenty, Domy, Działki, Pensjonaty, Hotele, Lokale użytkowe...
> > > Kliknij:http://klik.wp.pl/?adr=www.nieruchomosciwzakopanem.pl&sid=652
>
> > >  lab1003.doc
> > > 39KAfficherTélécharger
>
>

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to