0% found this document useful (0 votes)
214 views2 pages

csc113 Lab 6

This document describes classes that implement polymorphism based on a class diagram. It includes descriptions of the Point, Shape, Circle, Rectangle, and ShapeArray classes, including their constructors, getters, and methods like area(), toString(), addShape(), averageArea(), circleCount(), and rectangleCount(). The goal is to implement these classes according to the specifications and test them using a ShapeArrayProgram class with a main method.

Uploaded by

Ebtisam Hamed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
214 views2 pages

csc113 Lab 6

This document describes classes that implement polymorphism based on a class diagram. It includes descriptions of the Point, Shape, Circle, Rectangle, and ShapeArray classes, including their constructors, getters, and methods like area(), toString(), addShape(), averageArea(), circleCount(), and rectangleCount(). The goal is to implement these classes according to the specifications and test them using a ShapeArrayProgram class with a main method.

Uploaded by

Ebtisam Hamed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

CSC

 113                                                                                                                                King  Saud  University  


Lab  6        Department  of  Computer  Science  
 
Lab/Tutorial  6:  Polymorphism  

 
 
Determine  abstract  classes  and  methods  in  the  above  class  diagram.  Then  use  
the  above  diagram  and  the  information  below  to  implement  classes:  Point,  Shape,  
Circle,  Rectangle,  ShapeArray.  
 
Point:  
• public    Point(int  x,  int  y):  Constructor  with  two  parameters  that  initializes  
a  Point  object.  
• Getters  
• public  String  toString():  overrides  method  toString()  to  return  a  point  
object  as  a  string.  Example:  it  returns  strings  “(1,2)”  ,  “(2,4)”  ,  etc.  
 
Shape:  
• public  Shape(Point  center):  constructor  with  one  parameter  to  initialize  a  
Shape  object.  
• public  double  area  ():  returns  area  of  a  Shape  object.  
 
Circle:  
• public  Circle(Point  center,  int  radius):  Constructor  to  initialize    a  Circle  
obejct.  
• Getter  
• public  String  toString():  overrides  inherited  toString()  method  to  include  
the  Circle  Object’s  radius  in  the  returned  string.  
 
Rectangle    
• public  Rectangle(Point  center,  int  length,  int  width):  Constructor  to  
initialize  a  Rectangle  object.  
• Getters  
• public  String  toString():  overrides  inherited  toString()  method  to  include  
the  Rectangle  Object’s  length,  width  in  the  returned  string.  
 
CSC  113                                                                                                                                King  Saud  University  
Lab  6        Department  of  Computer  Science  
 
ShapeArray  
• public  ShapeArray(int  size):  Constructor  that  initializes  a  ShapeArray  
object.  
• public  boolean  addShape(Shape  shape):  adds  a  Circle  or  Rectangle  object  
to  ShapeArray  object,  returns  true  if  added  or  false  otherwise.  
• public  double  averageArea():  returns  the  average  area  of  Rectangle  and  
Circle  objects  in  a  ShapeArray  object.  
• public    int  circleCount():  returns  the  number  of  Circle  objects  in  a  
ShapeArray  object.  
• public  int  rectangleCount():  returns  the  number  of  Rectangle  objects  in  
ShapeArray  object.  
 
Write  a  class  called  ShapeArrayProgram  with  main  method  to  test  all  
the  methods  of  ShapeArray  

You might also like