• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help for importing classes  RSS feed

 
Nitesh Panchal
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello folks,
This is my 1st post, so please bear with me. I am trying to import my user defined class but it's not working. Can you tell me what the problem can be?Here's the code for Rect class saved in Rect.java



and here's the Area class that makes use of Rect class




Also note that both the classes are in same directory, but still it's not working. Please help me?

[edit]Add code tags[/edit]
[ December 23, 2008: Message edited by: Campbell Ritchie ]
 
Nitesh Panchal
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Rect's parameterised constructor the parameters should be of type double but by mistake i wrote int.
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch

Please find the Code Button; it preserves indentation. I have been back to your post and you can see how much better it looks.

Suggest you delete the no-arguments constructor from the Rect class; make people using the class specify a size.

You are requiring two command-line arguments, but not actually using them.

The problem about imports is that you are not allowed to import a class without a package name. If the two classes are in the same folder, simply delete the import statement.
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Campbell Ritchie:
Suggest you delete the no-arguments constructor from the Rect class; make people using the class specify a size.

Campbell, Could you please elaborate on this?
[ December 23, 2008: Message edited by: Vishal Pandya ]
 
laborc hu
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello !
if your classes are in same directory,you can not import Rect in Area.
In Rect's parameterised constructor the parameters should be of type double.Otherwise,your code will not pass compiler
 
Amit Ghorpade
Bartender
Posts: 2856
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"chotta chatri" please check your private messages for an important administrative matter. You can see them by clicking the My Private Messages link above.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!