Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you help to solve this problem? # Square class - text based # Allows you to change set initial data, then change the data,

Can you help to solve this problem?

# Square class - text based # Allows you to change set initial data, then change the data, and show the square as text # Because of fonts, squares will probably not show as exactly square

class Square(): """Represents a square """

def __init__(self, size, hChar, vChar, cornerChar): ''' Initializes a square Pass in the size, the character to used for the horizontal edge, vertical edge, and corners. ''' self.size = size self.hChar = hChar self.vChar = vChar self.cornerChar = cornerChar

def show(self): ''' Print the square in text using the horizontal edge, vertical edge, and corner characters Use a space (' ') for all characters not on an edge ''' print() print('This line should be replaced with lines to draw this Square.')

def getSize(self): ''' Returns the size of an edge of the Square ''' pass

def setHorizontalChar(self, newHChar): ''' Set a new horizontal character ''' pass def setVerticalChar(self, newVChar): ''' Set a new vertical character ''' pass

def setCornerChar(self, newCornerChar): ''' Set a new corner character ''' pass

# Must add 2 additional methods: setSize and getArea

# Test code # Create a square of size 5 oSquare1 = Square(5, '-', '|', '*') # pass in size, horizonal, vertical, and edge characters oSquare1.show() print('Size is:', oSquare1.getSize(), " area is:", oSquare1.getArea())

# Create another square of size 10 oSquare2 = Square(10, '-', '|', '*') oSquare2.show() print('Size is:', oSquare2.getSize(), " area is:", oSquare2.getArea())

# Tell the first square to modify its data oSquare1.setSize(7) oSquare1.setHorizontalChar('^') oSquare1.setVerticalChar('?') oSquare1.setCornerChar('$') oSquare1.show() print('Size is:', oSquare1.getSize(), " area is:", oSquare1.getArea()) print()

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_2

Step: 3

blur-text-image_3

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

Expert Oracle9i Database Administration

Authors: Sam R. Alapati

1st Edition

1590590228, 978-1590590225

More Books

Students also viewed these Databases questions

Question

How are FICO scores used in classifying loans?

Answered: 1 week ago

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago