Question

In: Computer Science

1. Write a superclass encapsulating a rectangle. A rectangle has two attributes representing the width and...

1. Write a superclass encapsulating a rectangle. A rectangle has two attributes representing the width and the height of the rectangle. It has methods returning the perimeter and the area of the rectangle. This class has a subclass, encapsulating a parallelepiped, or box. A parallelepiped has a rectangle as its base, and another attribute, its length; it has two methods that calculate and return its area and volume. You also need to include a client class (with the main method) to test these two classes i need this in python

Solutions

Expert Solution

Answer: here is the answer for your question:

code:

----------------------------------------------------------------------------------------------------------------------------------------------------------------------

class rectangle(object):

def __init__(self,width,height):
self.width=width
self.height=height

def cal_perimeter(self):
return 2*self.width*self.height

def cal_area(self):
return self.width*self.height

class Box(rectangle):
def __init__(self,width,height,length):
self.length=length
rectangle.__init__(self,width,height)


def box_area(self):
return self.width*self.height

def box_volume(self):
return self.width*self.height*self.length

if __name__ == '__main__':

obj1=rectangle(20,40)
print("perimeter of rectangle is :"+str(obj1.cal_perimeter()))
print("Area of rectangle is :"+str(obj1.cal_area()))
  

obj2=Box(10,20,30)
print("Area of rectangle is : "+str(obj2.box_area()))
print("perimeter of rectangle is :"+str(obj2.box_volume()))
print("END OF PROGRAM ")

----------------------------------------------------------------------------------------------------------------------------------------------------------------------

OUTPUT:

I hope this would help you out

If you have any doubt, you can provide comment /feedback below the answer

Thanks

  
  


Related Solutions

1. Write a class called Rectangle that maintains two attributes to represent the length and width...
1. Write a class called Rectangle that maintains two attributes to represent the length and width of a rectangle. Provide suitable get and set methods plus two methods that return the perimeter and area of the rectangle. Include two constructors for this class. One a parameterless constructor that initializes both the length and width to 0, and the second one that takes two parameters to initialize the length and width. 2. Write a java program (a driver application) that tests...
(Rectangle Class) Create class Rectangle. The class has attributes length and width, each of which defaults...
(Rectangle Class) Create class Rectangle. The class has attributes length and width, each of which defaults to 1. It has read-only properties that calculate the Perimeter and the Area of the rectangle. It has properties for both length and width. The set accessors should verify that length and width are each floating-point numbers greater than 0.0 and less than 20.0. Write an app to test class Rectangle. this is c sharp program please type the whole program.
Write a class encapsulating a board game. A board game has the following additional attributes: the...
Write a class encapsulating a board game. A board game has the following additional attributes: the number of players and whether the game can end in a tie. Code the constructor and the toString method of the new class. You also need to include a client class(with the main method) to test your code. code in Python
using java Create a class Rectangle with attributes length and width both are of type double....
using java Create a class Rectangle with attributes length and width both are of type double. In your class you should provide the following: Provide a constructor that defaults length and width to 1. Provide member functions that calculate the area, perimeter and diagonal of the rectangle. Provide set and get functions for the length and width attributes. The set functions should verify that the length and width are larger than 0.0 and less that 50.0. Provide a member function...
Write the definition for a generic class called Rectangle that has data members length and width....
Write the definition for a generic class called Rectangle that has data members length and width. The class has the following member functions: setlength to set the length data member setwidth to set the width data member perimeter to calculate and return the perimeter of the rectangle area to calculate and return the area of the rectangle show to return a text to display the length and width of the rectangle sameArea that has one parameter of type Rectangle. sameArea...
Write the definition for a generic class called Rectangle that has data members length and width....
Write the definition for a generic class called Rectangle that has data members length and width. The class has the following member functions: setlength to set the length data member setwidth to set the width data member perimeter to calculate and return the perimeter of the rectangle area to calculate and return the area of the rectangle show to return a text to display the length and width of the rectangle sameArea that has one parameter of type Rectangle. sameArea...
This is python #Create a class called Rectangle. Rectangle should #have two attributes (instance variables): length...
This is python #Create a class called Rectangle. Rectangle should #have two attributes (instance variables): length and #width. Make sure the variable names match those words. #Both will be floats. # #Rectangle should have a constructor with two required #parameters, one for each of those attributes (length and #width, in that order). # #Rectangle should also have a method called #find_perimeter. find_perimeter should calculate the #perimeter of the rectangle based on the current values for #length and width. # #perimeter...
A rectangle has a length of 10 inches and a width of 6 inches. If the length is increased by x inches and the width increased
For the following exercises, use the written statements to construct a polynomial function that represents the required information.A rectangle has a length of 10 inches and a width of 6 inches. If the length is increased by x inches and the width increased by twice that amount, express the area of the rectangle as a function of x.  
Write a class encapsulating the concept of the weather forecast, assuming that it has the following...
Write a class encapsulating the concept of the weather forecast, assuming that it has the following attributes: the temperature and the sky conditions (e.g. sunny, snowy, cloudy, rainy, etc.).  Include a default constructor, an overloaded constructor, accessors and mutators, and the methods, toString() and equals(). Temperature, in Fahrenheit, should be between -50 and +150; the default value is 70, if needed. The default sky condition is sunny. In Addition, include a method that converts Fahrenheit to Celsius. Celsius temperature = (Fahrenheit...
Write a class encapsulating the concept of a Student, assuming that the Student has the following...
Write a class encapsulating the concept of a Student, assuming that the Student has the following attributes: the name of the student, the average of the student, and the student’s GPA. Include a default constructor, an overloaded constructor, the accessors and mutators, and methods toString() and equals(). Also include a method returning the letter grade base on the following range for the average: Average Range Letter Grade 90-100 A 85-89   B+ 80-84 B 75-79 C+ 70-74 C 65-69 D+ 60-64...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT