Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need to add this to the code below Add a Square class and a Triangle class to the Shapes example gone over in class

I need to add this to the code below

Add a Square class and a Triangle class to the Shapes example gone over in class and test your implementation.

using System; namespace Shapes { public abstract class Shape { private int x; private int y; public Shape(int newX, int newY) { setX(newX); setY(newY); } public void setX(int newx) { x = newx; } public void setY(int newy) { y = newy; } public int getX() { return x; } public int getY() { return y; } public void moveTo(int newX, int newY) { setX(newX); setY(newY); } public void rMoveTo(int deltaX, int deltaY) { moveTo(deltaX + getX(), deltaY + getY()); } public abstract void draw(); } public class Rectangle : Shape { private int width; private int height; public Rectangle(int newX, int newY, int newW, int newH) : base(newX, newY) { setWidth(newW); setHeight(newH); } public void setWidth(int newW) { width = newW; } public void setHeight(int newH) { height = newH; } public int getWidth() { return width; } public int getHeight() { return height; } public override void draw() { Console.WriteLine("Drawing a rectangle starting at: " + getX() + ", " + getY()); } } public class Circle : Shape { private int radius; public Circle(int newX, int newY, int newR) : base(newX, newY) { setRadius(newR); } public void setRadius(int newR) { radius = newR; } public int getRadius() { return radius; } public override void draw() { Console.WriteLine("Drawing a circle starting at: " + getX() + ", " + getY()); } } class Program { static void Main(string[] args) { Rectangle r1 = new Rectangle(1, 1, 3, 5); // r1.draw(); r1.moveTo(2, 3); //r1.draw(); Circle c1 = new Circle(3, 5, 4); // c1.draw(); c1.rMoveTo(1, 1); //c1.draw(); Shape[] scribble = new Shape[2]; scribble[0] = r1; scribble[1] = c1; for (int i = 0; i < scribble.Length; ++i) { scribble[i].draw(); scribble[i].moveTo(4, 8); scribble[i].draw(); } } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Development For Dummies

Authors: Allen G. Taylor

1st Edition

978-0764507526

More Books

Students also viewed these Databases questions