Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can we re-adapt this python code according to the requested information? I need python code. import math class Shape: def __init__(self, id=0, name=Shape, borderColor=Black): self.id=id

Can we re-adapt this python code according to the requested information? I need python code.

import math

class Shape: def __init__(self, id=0, name="Shape", borderColor="Black"): self.id=id self.name=name self.borderColor = borderColor

def CalculatePerimeter(self): return "not computable"

def CalculateArea(self): return "not computable"

def __str__(self): return f"[{self.id}] {self.name}"

class Rectangle(Shape): def __init__(self, id, name, borderColor, width, length): self.width=width self.length=length

super().__init__(id, name, borderColor)

def CalculatePerimeter(self): return 2 * (self.length + self.width)

def CalculateArea(self): return self.length * self.width

def __str__(self): p = self.CalculatePerimeter() a = self.CalculateArea()

return f"Rectangle: [{self.id}] {self.name} | Area is {a}, Perim is {p}"

class Circle(Shape): def __init__(self, id, name, borderColor, diameter, angle=360): self.diameter = diameter self.angle = angle self.radius = self.diameter / 2

super().__init__(id, name, borderColor)

def CalculateArea(self): return round(math.pi * self.radius**2 * self.angle/360, 2)

def CalculatePerimeter(self): return round(math.pi * self.diameter, 2)

def __str__(self): p = self.CalculatePerimeter() a = self.CalculateArea()

return f"Circle: [{self.id}] {self.name} | Area is {a}, Perim is {p}"

class Triangle(Shape): def __init__(self, id, name, borderColor, base, height, sideLeft, sideRight): self.base = base self.height = height self.sideLeft = sideLeft self.sideRight = sideRight

super().__init__(id, name, borderColor)

def CalculatePerimeter(self): return self.base + self.sideLeft + self.sideRight

def CalculateArea(self): return self.base * self.height / 2

def __str__(self): p = self.CalculatePerimeter() a = self.CalculateArea()

return f"Triangle: [{self.id}] {self.name} | Area is {a}, Perim is {p}"

def add_shape(): shape_type = input("Enter the type of shape (rectangle, circle, triangle): ") id = int(input("Enter the id of the shape: ")) name = input("Enter the name of the shape: ") border_color = input("Enter the border color of the shape: ")

if shape_type == "rectangle": width = int(input("Enter the width of the rectangle: ")) length = int(input("Enter the length of the rectangle: ")) shape_list.append(Rectangle(id, name, border_color, width, length)) elif shape_type == "circle": diameter = int(input("Enter the diameter of the circle: ")) angle = int(input("Enter the angle of the circle: ")) shape_list.append(Circle(id, name, border_color, diameter, angle)) elif shape_type == "triangle": base = int(input("Enter the base of the triangle: ")) height = int(input("Enter the height of the triangle: ")) side_left = int(input("Enter the left side of the triangle: ")) side_right = int(input("Enter the right side of the triangle: ")) shape_list.append(Triangle(id, name, border_color, base, height, side_left, side_right)) else: print("Invalid shape type")

def display_all_shapes(): for shape in shape_list: print(shape)

def display_single_shape(): id = int(input("Enter the id of the shape: "))

for shape in shape_list: if shape.id == id: print(shape) break else: print("Shape with the given id not found")

shape_list = []

while True: print("1. Add a shape") print("2. Display all shapes") print("3. Display a single shape") choice = int(input("Enter your choice: "))

if choice == 1: add_shape() elif choice == 2: display_all_shapes() elif choice == 3: display_single_shape() else: break

image text in transcribed

image text in transcribed

In this lab assignment, you need to repeat the inclass programming exercise for a different scenario. The interface and the functionality will be the same, but they need to be adopted to different classes. In the lecture, there were Circle, Triangle, and Rectangle classes deriving from the Shape class. Differently, in this assignment, you need to create the FootballTeam and BasketballTeam classes that derive from the Team class. As in the Shapes application, the user should be able to add a new team, display details of a selected team, and list all teams by their id and name. The properties and the methods of all classes that you need to create are given below. Team class attributes: league instance attributes: id, name, wins, defeats, scoresAchieved, scoresConceded, average (which is equal to scoresAchieved - scoresConceded). Football Team instance attributes: draws functions: calculateMatchsPlayed() \#should return wins + defeats + draws calculatePoints () \#should return wins * 3+ draws team, display details of a selected team, and list all teams by their id and name. The properties and the methods of all classes that you need to create are given below. Team class attributes: league instance attributes: id, name, wins, defeats, scoresAchieved, scoresConceded, average (which is equal to scoresAchieved - scoresConceded). Football Team instance attributes: draws functions: calculateMatchsPlayed() \#should return wins + defeats + draws calculatePoints() \#should return wins * 3+ draws Basketball Team instance attributes: totalFauls, totalRebounds functions: calculateMatchsPlayed() \#should return wins + defeats calculatePoints () \#should return wins * 2+ defeats

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

Transactions On Large Scale Data And Knowledge Centered Systems Xxiv Special Issue On Database And Expert Systems Applications Lncs 9510

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Hendrik Decker ,Lenka Lhotska ,Sebastian Link

1st Edition

366249213X, 978-3662492130

More Books

Students also viewed these Databases questions

Question

b. What groups were most represented? Why do you think this is so?

Answered: 1 week ago

Question

3. Describe phases of minority identity development.

Answered: 1 week ago

Question

5. Identify and describe nine social and cultural identities.

Answered: 1 week ago