Question

python code? 1. Create a class called Person that has 4 attributes, the name, the age,...

python code?



1. Create a class called Person that has 4 attributes, the name, the age, the weight and the height [5 points]

2. Write 3 methods for this class with the following specifications.
a. A constructor for the class which initializes the attributes [2.5 points]

b. Displays information about the Person (attributes) [2.5 points]

c. Takes a parameter Xage and returns true if the age of the person is older than Xage, false
otherwise [5 points]

3. Create another class employee that inherits from class Person, with it`s own attributes salary and age. [5 points]

4. Write 3 methods for this class with the following specifications.
a. Sets the attribute Salary [5 points]

b. Sets the attribute age. [5 points]

c. Returns salary and age of the employee object in a list, where first element will be the salary and second will be the age. [5 points]

5. Create an object from class Person and call its method to display information.

6. Ask to user to enter an age. Call method of Person with the age user entered and print if the object created in 5 is older. [5 points]

7. Create another object from class Employee and call the method to display information [5 points]

8. Ask the user to enter salary and the age of the employee and set it`s attributes. [5 points]

9. Use the method of employee to print salary and age of the employee object. [5 points]

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

Answer: Hey dear student find the solution of your query if you have any doubt feel free to ask. Thanks!!

Each question answered in this program, please study it carefully. Before run an exact match with screenshots of the code. Possible screenshots have been attached. Python code won't run without proper indentation so be careful.

If any issue asks in the comment box.

Copy to code:

class Person: #class Person
def __init__(self, name, age,height,weight): #4attributes constructor that initialized them
self.name = name
self.age = age
self.height = height
self.weight = weight
def display(self,xage):#function to print Person class object that takes one parameter
print("Name: ",self.name)
if (self.age>xage):#check if older than xage then print TRUE
print("TRUE")
else:
print("FALSE")#FALSE
print("Age: ",self.age)
print("Height:",self.height)
print("Weight:",self.weight)
class Employee(Person):#Employee class that inherits from Person class
   def __init__(self):
       self.salary = 0.0
       self.age = 0
   def setage(self,ag):#set age
       self.age = ag
   def setSalary(self,sal):#set salary
       self.salary = sal
   def returnObjects(self):#returning objects
       return self.age,self.salary
print("class Person Object 2: "   )
p1 = Person("John", 36,5.6,67.5)#Person object create
p1.display(45)#call display() with passing parameter
li = []
ag = input("Enter age of Employee: ")#ask for age of Employee
sal = input("Enter Salary of Employee: ")#ask for Salary of the Employee
e1 = Employee()#create object of the Employee class
e1.setage(ag)#call setters
e1.setSalary(sal)
li = e1.returnObjects()#returns object into list
print("Age : ",li[0])#print list
print("Salary: $",li[1])


This is the Person class with 4 attributes and has one constructor and print information through display()

name 6 8 main.py 1. class Person: #class Person 2 def __init__(self, name, age, height, weight): #4attributes constructor tha

This Person class same as above but display() is taking one parameter to check age and print message.

name main.py 1 class Person: #class Person 2 def __init__(self, name, age, height, weight): #4attributes constructor that ini

This is Employee class with two attributes age ,salary.Setters and return objects.

Creates object of Employee class and call setters,call retrunobjects() into list.print elements of the list

= 0 class Employee (Person) :#Employee class that inherits from Person class def __init__(self): self.salary self.age def set

main.py 20 def setage(self, ag): 21 self.age = ag 22 def setSalary(self,sal): 23 self.salary = sal 24. def returnObjects(self

20 def setage(self, ag): 21 self age = ag 22 def setSalary(self,sal): 23 self.salary sal 24- def returnObjects(self): 25 retu

Add a comment
Know the answer?
Add Answer to:
python code? 1. Create a class called Person that has 4 attributes, the name, the age,...
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
  • create java application with the following specifications: -create an employee class with the following attibutes: name...

    create java application with the following specifications: -create an employee class with the following attibutes: name and salary -add constuctor with arguments to initialize the attributes to valid values -write corresponding get and set methods for the attributes -add a method in Employee called verify() that returns true/false and validates that the salary falls in range1,000.00-99,999.99 Add a test application class to allow the user to enter employee information and display output: -using input(either scanner or jOption), allow user to...

  • reate a class called Person with the following attributes: name - A string representing the person's...

    reate a class called Person with the following attributes: name - A string representing the person's name age - An int representing the person's age in years As well as appropriate __init__ and __str__ methods, include the following methods: get_name(self) - returns the name of the person get_age(self) - returns the age of the person set_name(self, new_name) - sets the name for the person set_age(self, new_age) - sets the age for the person is_older_than(self, other) - returns True if this...

  • create a java class named Person that has 3 attributes: name, age and weight. include a...

    create a java class named Person that has 3 attributes: name, age and weight. include a default and parametrize constructor. include all setters and getters needed and a method that is used to display the information about the person

  • Create the Python code for a program adhering to the following specifications. Write an Employee class...

    Create the Python code for a program adhering to the following specifications. Write an Employee class that keeps data attributes for the following pieces of information: - Employee Name (a string) - Employee Number (a string) Make sure to create all the accessor, mutator, and __str__ methods for the object. Next, write a class named ProductionWorker that is a subclass of the Employee class. The ProductionWorker class should keep data attributes for the following information: - Shift number (an integer,...

  • Create a class “Person” which includes first name, last name, age, gender, salary, and haveKids (Boolean)...

    Create a class “Person” which includes first name, last name, age, gender, salary, and haveKids (Boolean) variables. You have to create constructors and properties for the class. Create a “MatchingDemo” class. In the main function, the program reads the number of people in the database from a “PersonInfo.txt” file and creates a dynamic array of the object. It also reads the peoples information from “PersonInfo.txt” file and saves them into the array. In C# Give the user the ability to...

  • PYTHON*************** Create a Person Class that: Accepts First Name, Last Name, Age, and Gender Has a...

    PYTHON*************** Create a Person Class that: Accepts First Name, Last Name, Age, and Gender Has a method that adds all persons Validate all input, not left empty for First Name, Last Name, Gender and numeric for age and throw an exception if it does not validate within the class. Create a Student Class that: Inherits the Person Class Accepts GPA Validate GPA (>= 0 and <= 4.0) and throw exception if it does not validate within the class. Has methods...

  • *Python* INTRODUCTION: The goal of this programming assignment is to enable the student to practice object-oriented...

    *Python* INTRODUCTION: The goal of this programming assignment is to enable the student to practice object-oriented programming using classes to create objects. PROBLEM DEFINITION: Write a class named Employee that holds the following data about an employee in attributes: name, IDnumber, department, jobTitle The class should have 8 methods as follows:  For each attribute, there should be a method that takes a parameter to be assigned to the attribute. This is known as a mutator method.  For each...

  • Design and implement class Circle to represent a circle object. The class defines the following attributes...

    Design and implement class Circle to represent a circle object. The class defines the following attributes (variables) and methods: 1.      A private variable of type double named radius to represent the radius. Set to 1. 2.      Constructor Methods: •        Python : An overloaded constructor method to create a default circle. •        C# & Java: Default Constructor with no arguments. •        C# & Java: Constructor method that creates a circle with user-specified radius. 3.      Method getRadius() that returns the radius. 4.     ...

  • Python 3> Make a class called BMW: Parameterized constructor with three instance variables (attributes): Hint: def...

    Python 3> Make a class called BMW: Parameterized constructor with three instance variables (attributes): Hint: def __init__(self, make, model, year) Methods in BMW parent class (can leave as method stubs for now): startEngine() -must print "The engine is now on." stopEngine() -must print "The engine is now off." Make another class called ThreeSeries -Must inherit BMW Hint: class ThreeSeries(BMW): -Also passes the three attributes of the parent class and invoke parent Hint: BMW.__init__(self, cruiseControlEnabled, make, model, year) -Constructor must have...

  • Write a class called Student. The specification for a Student is: Three Instance fields name -...

    Write a class called Student. The specification for a Student is: Three Instance fields name - a String of the student's full name totalQuizScore - double numQuizesTaken - int Constructor Default construtor that sets the instance fields to a default value Parameterized constructor that sets the name instance field to a parameter value and set the other instance fields to a default value. Methods setName - sets or changes the student name by taking in a parameter getName - returns...

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