Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help fast plz!!!!!!

 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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 !!
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have another question, what is the this modifier for?
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
lol thx for the geom. lesson forgot that
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thx!, i knew there was one, i was putting Math.pie, lol...thx alot!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic