• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

cannot find symbol compile error

 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Thompkins wrote:
I found this "For convenience, the Java compiler automatically imports three entire packages for each source file: (1) the package with no name, (2) the java.lang package, and (3) the current package (the package for the current file)..." on stack overflow


This is not quite right.
The Java tutorial says "For convenience, the Java compiler automatically imports two entire packages for each source file: (1) the java.lang package and (2) the current package (the package for the current file).".
Note: The current package can be either the package declared in the class file or, if there is no package declaration, the unnamed packaged.
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Thompkins wrote:Hi Knute, when you wrote

all classes are data types

does that also go for classes which I make myself? would I be correct in saying my poodle is not only of type dog but is of data type dog? if a create the following object:

Dog poodle = new Dog();




Absolutely. When you create a class, you have created a data type.


String is part of java.lang which is imported by default. I believe it is the only package that is. (Can anyone confirm?)


I found this "For convenience, the Java compiler automatically imports three entire packages for each source file: (1) the package with no name, (2) the java.lang package, and (3) the current package (the package for the current file)..." on stack overflow

I'm not quite sure what the 2 other packages besides java.lang are, it seems as though they are related to programmer created packages, I haven't read about putting my classes into own packages in headfirstjava yet but it was briefly mentioned earlier in the book that' it's possible.



Yes, it's coming back to me. The package with no name is probably the package you have been creating classes in. You get it when you don't have a package statement at the top of your program. And since package names relate to folders, you could be cd'd into a package when you start Java, which would be the current package.

Edit: it looks like I'm wrong about this: it's either the unnamed package, if you have no package statement, or the current package if you do.
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



My theoretical solution... it took me a longgg time to come up with the above solution so go easy on me, I've had a look at the hasnextint() method and I'm unable to see how I could implement it (in syntax) maybe I could come up with something in theory. I'm not sure whether I feel as though I'm making progress or not =/.

David

 
David Thompkins
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh dear... I haven't noticed the replies posted on here yesterday until now, page 2 was hiding from me... rather embarrassing! Not to be rude but I shall read tomorrow as I'm about to log off for the night!

David
 
Marshal
Posts: 79151
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't try using hasNextInt in that class. Create a KeyboardInputs class (or similar) which can be a utility class. Private constructor to prevent instantiation. All members are static. Private Scanner pointing to System.in, never closed. Method called getInt or similar using the sort of loop I showed earlier as Rob Spoor taught me ages ago. That is where you want hasNextInt. Then you can say
int i = KeyboardInputs.getInt("Enter number for ...");
…and let that class deal with all the error messages, etc.
 
David Thompkins
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Campbell, I'm about to cover static members in the next chapter.

currently I'm trying to write this but with an ArrayList.

This does not work

I've tried searching for a solution although I can't seem to find any, I've found how to scan input and place in arraylist I just cannot simply add values at two elements together, could someone please enlighten me?

Many thanks,

David

 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What happens when you use the code you commented out?
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are a and x? Is that an array of primitive numbers?

Stop trying to do so many things all at once. Array with [] for the indices or List with .get() for the indices. If you use get() on a List be sure to use the sort of List which implements RandomAccess. You will find the usual ArrayList does support random access.
 
See ya later boys, I think I'm in love. Oh wait, she's just a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic