File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Help fast plz!!!!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help fast plz!!!!!!" Watch "Help fast plz!!!!!!" New topic
Author

Help fast plz!!!!!!

Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802


ok, when i compile class circle, it says that class circle is not abstract,
and cant overide the methods in class Shape, why?...i dont want class circle to be abstract....

plz help !!


You down with OOP? Yeah you know me!
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
I get this error message:
Circle is not abstract and does not override abstract method CalA() in Shape
So it's not that it can't override a method, the error is that it doesn't. When you override a method, the number and type of parameters must be the same as the in the method you are overriding. In this case CalA must have no parameters.

Your code looks like it needs plent of work to get to the "correct" stage, but here is one hint: objects should know their own state, you shouldn't have to pass a radius to a circle's circumference or area methods (better method names, please, too!). The circle should already know its radius.


There is no emoticon for what I am feeling!
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Circle doesn't properly override the abstract methods in Shape because the versions in Circle take arguments, while the versions in Shape take none. The"signatures" (name, arguments, and return type (with some caveats)) have to be the same.

I know you're focussed on just getting this to compile, but I should point out a serious design problem here. You have member variables in Shape to store the circumference and the area, but you don't use them; instead you calculate these quantities from the radius, and you want radius passed in as an argument to those methods. Instead, radius wants to be a member, and since you're going to calculate the other quantities, they don't want to be members. If radius were a member of Circle, passed to Circle's constructor and then stored in a member variable, then it would be available for calC and calA to use. Perhaps Shape doesn't need any member variables of its own, at least for now.


[Jess in Action][AskingGoodQuestions]
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
no no no, ok, i have the two parameters circumference and area, that should pertain to all the shapes im going to instatiate.

but you can't instantiate an object of class shape because it is abstact..

the only thing the two methods are for is finding out the circ. or area..
if you dont know it...

so like


so if i want my methods to take parameters in the non - abstact methods,
then i need to declare it in the abstract ones??....

and if so....say i put in the abstract method two int parameters A and B.
do i have to have two parameters in the Circle classes' methods, or can i
choose to have one,

thanks,
Monk
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
oh yes, and by the way, all my shapes are going to have different parameters,

because to find the parameter for rectangle, is 2L + 2W, so i would need
a width parameter and Length...

and for a square i would just need one side to find Circ. and Area....
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
i have another question, what is the this modifier for?
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3739
    
  16
Originally posted by Monk Fox:



I know it's been a while since I did any geometry, but I think the area of a circle is


Joanne
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
i figured it out!!!

in the parameters for the shape, i used (double Circ., double area)

so in the child classes for example circle....all i had to do was..

super((double)2*(3.14)*A,(double)Math.pow((3.14*A),2);
// A being the parameter for circle when the object is created
example:

Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
lol thx for the geom. lesson forgot that
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Originally posted by Monk Fox:
i have another question, what is the this modifier for?


this isn't a modifier, its a keyword. It will get you a reference to the current object.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Originally posted by Monk Fox:
i figured it out!!!

in the parameters for the shape, i used (double Circ., double area)

so in the child classes for example circle....all i had to do was..

super((double)2*(3.14)*A,(double)Math.pow((3.14*A),2);
// A being the parameter for circle when the object is created

So you use parameter A for radius :roll:
By the way, reread that earlier remark about the formula for area.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Also, note that 3.14 isn't a very good approximation to pi, especially when the constant value "Math.PI" is available.
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
thx!, i knew there was one, i was putting Math.pie, lol...thx alot!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help fast plz!!!!!!