import math
class Point:
def __init__(self,x,y):
self.x = x
self.y = y
def move(self,x,y):
self.x += x
self.y += y
def __str__(self):
return "<"+ str(self.x) + "," + str(self.y) + ">"
class Shape:
def __init__(self, centrePoint, colour, width, height):
self.centrePoint = centrePoint
self.colour = colour
self.width = width
self.height = height
self.type = "Square"
def __init__(self, centrePoint, radius, colour):
self.type = "Circle"
self.radius = radius
self.colour = colour
self.centrePoint = centrePoint
def move(self,x,y):
self.centrePoint.move(x,y)
def getArea(self):
if (self.type == "Square"):
return self.width * self.height
elif (self.type == "Circle"):
return math.pi*(self.radius**2)
def __str__(self):
return "Center Point: " + str(self.centrePoint) + "\nColour: "+ self.Colour + "\nType: " + self.type + "\nArea: " + self.getArea()
class Rectangle (Shape):
def scale(self, factor):
self.scaleVertically(factor)
self.scaleHorizontally(factor)
def scaleVertically(self, factor):
self.height *= factor
def scaleHorizontally(self, factor):
self.width *= factor
class Circle (Shape):
def scale(self, factor):
self.radius * factor
それは私がこれまでに持っているコードです。Shape は抽象クラスを表し、他の 2 つのクラスはそれを継承することになっています。私にはまだハードコーディングされすぎて抽象ソリューションにはなりません。どうすれば改善できますか?