
3. Write Python code to define the Ellipse class with a reasonable number of properties and methods.
For this assignment, we are learning about inheritance. For the first question, I created a class Circle to inherit from the parent class, Ellipse, using pass. For this question, I had to write a working code using class Ellipse, showing some properties and methods. I wanted to make sure I did it correctly and commented correctly. Any help would be appreciated, thanks.
----------------------------------------------------------------------------------------------------------
import math
# create parent class - ellipse
class Ellipse:
# parent class instance attribute
def __init__(self, length, width):
self.length = length
self.width = width
# use math.pi for value of pi
# calculate and return area of ellipse
def area(self):
return math.pi * self.length * self.width
# calculate and return perimeter of ellipse
def perimeter(self):
return math.pi * (self.length + self.width)
# create child class - circle
class Circle(Ellipse):
# child class instance attribute
def __init__(self, radius):
# super function used to inherit from parent class
super().__init__(radius, radius)
# to get radius
def getRadius(self):
return self.length
def main():
# enter and read length and width of the ellipse
length = float(input('Enter the length of ellipse: '))
width = float(input('Enter the width of ellipse: '))
# create an object of the ellipse class
e = Ellipse(length, width)
# display ellipse length/width/area/perimeter
print('Ellipse Length: ', e.length)
print('Ellipse Width: ', e.width)
print('Ellipse Area: ', e.area())
print('Ellipse Perimeter: ', e.perimeter())
# enter and read radius of the circle
radius = float(input('Enter the radius of circle: '))
# create an object of the circle class
c = Circle(radius)
# display circle radius/area/perimeter
print('Circle Radius: ', c.getRadius())
print('Area: ', c.area())
print('Perimeter: ', c.perimeter())
# call main function to start executing program
main()

Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images

- Write a code using abstract data types, classes, and inheritance methods as in the example below. Do not use the car class exemplified, but think of any similar use of such a class and adapt it to your idea. Make sure to follow all the requirements set below: Creating the Car Class Motorvehicles Solutions, Inc. is a business that sells cars and leasing services. You are a programmer in the company's IT department, and your team is designing a program to manage all of the cars that are in the inventory. You have been asked to design a class that represents a car. The data that should be kept as attributes in the class are as follows: The name of the car's manufacturer will be assigned to the __manufact attribute. The car's model number will be assigned to the __model attribute The car's retail price will be assigned to the __retail_price attribute The car's leasing price will be assigned to the __leasing_price attribute The class will also have the following methods: An __init__…arrow_forwardMatch the correct answer to the question. The information passed to a method in its parenthesis is referred to as: A self-contained block of program code that carries out some action is referred to as: The ability to create classes that share the attributes and methods of existing classes but with more specific features is known as: What reads the byte-code in chunks and compiles the chunk to machine language? Java identifier must not start with ……. and all the characters must be letters, digits, or the underscore ( _ ) symbol A. Inheritance B. JIT Compiler C.…arrow_forwardDirections: SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA. Notes: • Assume that the classes listed in the Java Quick Reference have been imported where appropriate. • Unless otherwise noted in the question, assume that parameters in method calls are not null and that methods are called only when their preconditions are satisfied. • In writing solutions for each question, you may use any of the accessible methods that are listed in classes defined in that question. Writing significant amounts of code that can be replaced by a call to one of these methods will not receive full credit. Consider a guessing game in which a player tries to guess a hidden word. The hidden word contains only capital letters and has a length known to the player. A guess contains only capital letters and has the same length as the hidden word. After a guess is made, the player is given a hint that is based on a comparison between the hidden word and the guess. Each position in the…arrow_forward
- Write a program in Java to perform the followings, (i) Design one parent and two child classes. Names of parent and child classes along with the names of their variables and methods should be taken from real-life by yourself. Parent class should have at least two variables, one parameterized constructor and one method to perform any meaningful operation/calculation with the variables. Child classes should have at least one additional variable declared within (ii) (iii) them and one parameterized constructor, and a toString method. (iv) Design another class and a main method inside it. Declare at least one object of each of the two child classes using parameterized constructor. Call the method of the parent class with these objects to perform the particular operation/calculation on these objects and show the result. Display values of all the variables of these objects using toString. Write the Java program using Eclipse IDE, copy and paste the code along with the output in a word file.…arrow_forwardProvide answers fastly and correctlyarrow_forwardIn the class diagram below we have a money class for an object-oriented parking system that is to be designed using java. Briefly explain any implementation decisions and the reasoning behind those without writing the complete code. N.B explain how the implementation will proceed instead of writing codearrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY





