Class Square Learn programming Visual Basic (VB.net)

Lesson:

Object Oriented Programming


Exercise:

Class Square 40


Objetive:

Complete the project named "Shapes" (january 8th), adding a class named "Square" to it. For each square, we will store its starting X and Y coordinates (the upper left corner, already stored as a "Location") and the length of its side.

You will have to create:
- A suitable constructor, to assign starting values to X, Y and the side. (2 points)
- A Move method, to change X and Y coordinates. (1 point)
- A Scale method, to change its side (for example, a scale factor of 2 would turn a side of 3 into 6). (1 point)
- A method ToString, to return a string with its data (for example: "Corner (10,5), side 7". (1 point)
- Redefine "GetPerimeter" and "GetArea", so that they return the correct values (2 points).

- Another point corresponds to the attributes and the overall structure.

- The remaining 2 points correspond to the test from "Main"

You must deliver a ZIP file containing the entire project.


Code:

Imports System

Namespace shapes
    Class Square
        Inherits Shape

        Private l As Location = New Location()

        Public Sub New(ByVal x As Double, ByVal y As Double, ByVal side As Double)
            l.SetX(x)
            l.SetY(y)
            l.SetSide(side)
        End Sub

        Public Sub Move(ByVal x As Double, ByVal y As Double)
            l.SetX(x)
            l.SetY(y)
        End Sub

        Public Sub Scale(ByVal factor As Integer)
            l.SetSide(l.GetSide() * factor)
        End Sub

        Public Function ToString() As String
            Return "Corner (" & l.GetX() / 2 & "), side " + l.GetSide()
        End Function
    End Class
End Namespace