100% Guaranteed Results


PCS – 1. Shapes Solved
$ 29.99
Category:

Description

5/5 – (1 vote)

a. Create a base class called “Shape” that includes 1 instance method – draw() make it virtual so that it can be overriden.
b. Create a subclass of the Shape class called “Circle”.
i. Make the Circle class have a private instance variable (field) – radius that determines how big the circle is. Add a public property for this field. ii. Create a constructor that accepts a radius – BUT still allow circles to be created with no radius passed in (provide a default constructor too). If no radius is passed in, default radius should be 5.
iii. Override the draw method in the circle class so that a circle of the correct radius is drawn (or a better use of your time – just print “Circle, radius X” instead of trying to figure out how to draw a circle in ASCII art.)
c. Create a subclass of the Shape class called “Square”.
i. Make the square class have a private instance variable (field) – size that determines how big each side of the square is. Add a public property for this field.
ii. Create a constructor that accepts a size – BUT still allow squares to be created with no size passed in (provide a default constructor too). If no size is passed in, default size should be 10.
iii. Override the draw method in the square class so that a square of the correct size is drawn (or again – just print “Square, size X” instead of trying to figure out how to draw a square in ASCII art – though a square is pretty easy.)
d. In the main method create an Array of type Shape to hold shapes and fill it with several different squares and circles.
e. Loop through the array calling draw on all the shapes and verify that all shapes are drawn correctly.
f. Change the radius and sizes of some of the existing circles and squares (remember casting).
g. Loop through the array calling draw on all the shapes and verify that all shapes are drawn correctly with the new values.
Extra Credit:
Override the equals method for the square class and test it out

Reviews

There are no reviews yet.

Be the first to review “PCS – 1. Shapes Solved”

Your email address will not be published. Required fields are marked *

Related products