SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Tony Gaddis
Chapter:
Classes And Object Oriented Programming
Exercise:
Programming Exercises
Question:4 | ISBN:9780132576376 | Edition: 2

Question

Write a class named Employee that holds the following data about an employee in attributes: 
name, ID number, department, and job title.
Once you have written the class, write a program that creates three Employee objects to hold the following data:

Name                   ID Number      Department            Job Title
Susan Meyers      47899             Accounting              Vice President
Mark Jones           39119             IT                             Programmer
Joy Rogers            81774            Manufacturing           Engineer

The program should store this data in the three objects and then display the data for each employee on the screen.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

#Create a class name, Employee that holds 
#the following data about an employee in attributes: 
name, ID number, department, and job title.
class Employee:
    def __init__(self, name, id_number, department, job_title):
        self.name = name
        self.id_number = id_number
        self.department = department
        self.job_title = job_title

# Create three Employee objects with the provided data
employee1 = Employee("Susan Meyers", 47899, "Accounting", "Vice President")
employee2 = Employee("Mark Charless", 39119, "IT", "Programmer")
employee3 = Employee("Joy Rogers", 81774, "Manufacturing", "Engineer")

# Display the data for each employee
print("Employee 1:")
print("Name:", employee1.name)
print("ID Number:", employee1.id_number)
print("Department:", employee1.department)
print("Job Title:", employee1.job_title)

print("\nEmployee 2:")
print("Name:", employee2.name)
print("ID Number:", employee2.id_number)
print("Department:", employee2.department)
print("Job Title:", employee2.job_title)

print("\nEmployee 3:")
print("Name:", employee3.name)
print("ID Number:", employee3.id_number)
print("Department:", employee3.department)
print("Job Title:", employee3.job_title)

Executed Output:

Employee 1:
Name: Susan Meyers
ID Number: 47899
Department: Accounting
Job Title: Vice President

Employee 2:
Name: Mark Jones
ID Number: 39119
Department: IT
Job Title: Programmer

Employee 3:
Name: Joy Rogers
ID Number: 81774
Department: Manufacturing
Job Title: Engineer

 

0 0

Discussions

Post the discussion to improve the above solution.