Question

Please show all work and answer all parts using python, thanks!

Instructions You will need to create four files: • Shape2D.py - file containing a class definition containing properties alls1 = Shape2D(blue) 51.getShapeProperties() Output: Shape: N/A, Color: blue Note: The s1.getShape Properties () return valueSquare.py The Square.py file will contain the definition of what a 2D Square will have. Since a Square IS-A 2D Shape, we will

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Shape2D.py

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 20 10:14:24 2020

@author: vibhav
"""

class Shape2D:
    color = ""
    def __init__(self, color):
        self.color = color
      
    def getColor(self):
        return self.color
  
    def getShapeProperties(self):
        return 'Shape: N/A, ' + 'Color: ' + self.color

Circle.py

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 20 10:23:15 2020

@author: vibhav
"""

import math
from Shape2D import Shape2D

class Circle(Shape2D):
    def __init__(self, color, radius):
        super().__init__(color)
        self.radius = radius
      
    def getRadius(self):
        return self.radius

    def setRadius(self, radius):
        self.radius = radius
      
    def computeArea(self):
        return math.pi *self.radius*self.radius
  
    def computePerimeter(self):
        return 2*math.pi*self.radius
  
    def getShapeProperties(self):
        return_str = 'Shape: CIRCLE, '
        return_str += 'Color: ' + self.color
        return_str += ', Radius: ' + str(self.radius)
        return_str += ', Area: ' + str(self.computeArea())
        return_str += ', Perimeter: ' + str(self.computePerimeter())
        return return_str
  
   Square.py

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 20 10:40:47 2020

@author: vibhav
"""

from Shape2D import Shape2D

class Square(Shape2D):
    def __init__(self, color, side):
        super().__init__(color)
        self.side = side
      
    def getSide(self):
        return self.side
  
    def setSide(self, side):
        self.side = side
      
    def computeArea(self):
        return self.side*self.side
  
    def computePerimeter(self):
        return 4*self.side
  
    def getShapeProperties(self):
        return_str = 'Shape: SQUARE, '
        return_str += 'Color: ' + self.color
        return_str += ', Side: ' + str(self.side)
        return_str += ', Area: ' + str(self.computeArea())
        return_str += ', Perimeter: ' + str(self.computePerimeter())
        return return_str

test.py

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 20 10:17:12 2020

@author: vibhav
"""

from Shape2D import Shape2D
from Circle import Circle
from Square import Square

s1 = Shape2D('blue')
print(s1.getShapeProperties(),end="")

print()

c1 = Circle("blue", 2.5)
print(c1.getShapeProperties(),end="")

print()

s2 = Square('blue', 2.5)
print(s2.getShapeProperties(),end="")

#!/usr/bin/env python3 # -*- coding: utf-8 -*- Created on Tue Oct 20 10:14:24 2020 @author: vibhav - class Shape2D: color = d#!/usr/bin/env python3 # -*- coding: utf-8 -*- Created on Tue Oct 20 10:23:15 2020 @author: vibhav import math from Shape2D i#!/usr/bin/env python3 # -*- coding: utf-8 -*- Created on Tue Oct 20 10:40:47 2020 @author: vibhav from Shape2D import Shape2

#!/usr/bin/env python3 # -*- coding: utf-8 -*- AF AF Created on Tue Oct 20 10:17:12 2020 @author: vibhav from Shape 2D importIn [10]: runfile( /home/vibhav/testFile.py, wdir=/home/vibhav) Reloaded modules: Shape2D, Circle, Square Shape: N/A, Colo

Add a comment
Know the answer?
Add Answer to:
Please show all work and answer all parts using python, thanks! Instructions You will need to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python only please, thanks in advance. Type up the GeometricObject class (code given on the back...

    Python only please, thanks in advance. Type up the GeometricObject class (code given on the back of the paper). Name this file GeometricObjectClass and store it in the folder you made (xxlab14) 1. Design a class named Rectangle as a subclass of the GeometricObject class. Name the file RectangleClass and place it in the folder. 2. The Rectangle class contains Two float data fields named length and width A constructor that creates a rectangle with the specified fields with default...

  • Language is JAVA. Clarification for the Shape class (highlighted): The following requirements specify what fields you...

    Language is JAVA. Clarification for the Shape class (highlighted): The following requirements specify what fields you are expected to implement in your Shape class; - A private String color that specifies the color of the shape - A private boolean filled that specifies whether the shape is filled - A private date (java.util.date) field dateCreated that specifies the date the shape was created Your Shape class will provide the following constructors; - A two-arg constructor that creates a shape with...

  • Type up the GeometricObject class (code given on the back of the paper). Name this file Geometric...

    Python only please, thanks in advance. Type up the GeometricObject class (code given on the back of the paper). Name this file GeometricObjectClass and store it in the folder you made (xxlab14) 1. Design a class named Rectangle as a subclass of the GeometricObject class. Name the file RectangleClass and place it in the folder. 2. The Rectangle class contains Two float data fields named length and width A constructor that creates a rectangle with the specified fields with default...

  • 11p Python Language Read the following code for oofraction. import oofraction class OOFraction: def main(): fl...

    11p Python Language Read the following code for oofraction. import oofraction class OOFraction: def main(): fl = oofraction.o0Fraction( 2, 5) f2 = oofraction.o0Fraction ( 1, 3) f3 = f1 + f2 print (str(3)) main() def __init__(self, Num, Den): self.mNum = Num self.mDen = Den return def_add_(self,other): num = self.mNumother.mDen + other.mNum*self.mDen den = self.mDen*other.mDen f = OOFraction(num,den) return f 1. Write the output below. def_str_(self): s = str( self.mNum )+"/" + str( self.mDen) returns 2. Write a class called wholeNum...

  • You will be creating a driver class and 5 class files for this assignment. The classes...

    You will be creating a driver class and 5 class files for this assignment. The classes are Shape2D (the parent class), Circle, Triangle, and Rectangle (all children of Shape2D) and Square (child of Rectangle). Be sure to include a message to the user explaining the purpose of the program before any other printing to the screen. Within the driver class, please complete the following tasks: Instantiate a Circle object with 1 side and a radius of 4; print it Update...

  • Use Python 3 Create a program that uses Turtle to draw shapes. Show the following menu:...

    Use Python 3 Create a program that uses Turtle to draw shapes. Show the following menu: Enter Circle Enter Rectangle Remove Shape Draw Shapes Exit Circles – User inputs position, radius, and color. The position is the CENTER of the circle Rectangles – User inputs position, height, width, color. The position is the lower left-hand corner Colors – Allow red, yellow, blue, and green only Remove – Show the number of items in the list and let the user enter...

  • Written in python using puTTy!! i'm having a lot of trouble with this, will upvote! also...

    Written in python using puTTy!! i'm having a lot of trouble with this, will upvote! also here is the address.csv file Name,Phone,Email,Year_of_Birth Elizi Moe,5208534566,[email protected],1978 Ma Ta,4345667345,[email protected],1988 Diana Cheng,5203456789,[email protected],1970 ACTIVITY I Implement in Python the Subscriber class modeled by the UML diagram provided below. Save in a file called MyClasses.py Subscriber name: string yearOfBirth: int phone: string email: string getName() getAge() getPhone() getEmail() Write a test program that does the following: Read the file addresses.csv. For each record, create an object...

  • IN PYTHON Assignment Overview This assignment will give you experience on the use of classes. Understand...

    IN PYTHON Assignment Overview This assignment will give you experience on the use of classes. Understand the Application The assignment is to first create a class calledTripleString.TripleStringwill consist of threeinstance attribute strings as its basic data. It will also contain a few instance methods to support that data. Once defined, we will use it to instantiate TripleString objects that can be used in our main program. TripleString will contain three member strings as its main data: string1, string2, and string3....

  • This question is about java program. Please show the output and the detail code and comment.And...

    This question is about java program. Please show the output and the detail code and comment.And the output (the test mthod )must be all the true! Thank you! And the question is contain 7 parts: Question 1 Create a Shape class with the following UML specification: (All the UML "-" means private and "+" means public) +------------------------------------+ | Shape | +------------------------------------+ | - x: double | | - y: double | +------------------------------------+ | + Shape(double x, double y) | |...

  • Can you please help me with with problem. please follow all the specific insturctions, and try...

    Can you please help me with with problem. please follow all the specific insturctions, and try to make simple for a beginner in java. Write a class called Shape that contains instance data that represents the name and number of sides of the shape. Define a constructor to initialize these values. Include mutator(setter) methods – with the this reference – for the instance data, and a toString method that returns a the shape data. Create a static variable to keep...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT