java - Which data type should I use? -
i have set of data, lets call them shapes.
there 3 types of shapes:
1) circle : x-coordinate y-coordinate r-radius c-color 2) square: x-coordinate y-coordinate s-side c- color 3) line: x-coordinate y-coordinate x1-coordinate y1-coordinate c- color
which data type best suited them? should make shape class , make circle, square , line subclasses of shape? if do, can put of them in 1 class file?
as side note: when creating each shape, constructor given maxx , maxy. shaped autogenerated random numbers stay inbound within (0,0,maxx,maxy). sizes user-determined. keeping them 1/10 1/3 or width of screen. less-important details.
you have super class called shape
, have common properties (x-coordinate
, y-coordinate
, colour
).
you extend class circle
, square
, line
classes, wherein fill in properties each distinct item has. it recommended have separate class file each class.
this approach allow to, instance, create list<shape>
should need create collection of shapes.
Comments
Post a Comment