Question

In: Computer Science

For this project, you are to modify the Employee class posted on Blackboard by adding a...

For this project, you are to modify the Employee class posted on Blackboard by adding a bonus field. The bonus field should be equal to zero when an Employee object is created. You need to add a setter and a getter method to the new bonus field.

The Dirany’s company saves all employee information in the dirany.txt file (attached). The file saves each employee’s information in a new line and all attributes are separated by tabs. For example, the first employee’s information on the first line in the dirany.txt file is as follows:

John    Smith 90000

John is the first name of the employee, Smith is the employee’s last name and 90000 is the employee’s annual salary.

Your program should read the dirany.txt file and create an Employee object for each employee in the file, then add the employees to a queue data structure in the same order you read them from the file. The Dirany’s company saves the employees records according to their longevity in the company.

You need to help the Dirany’s company, to calculate the bonus for each employee according to their longevity rule so the bonus of the first employee will be 20% of his/her salary and for each employee afterwards the percent of the bonus will be 1%less so the second employee will get 19% of his/her salary, the third employee will get 18% of his/her salary and so forth.

Your program should access the Employees’ objects in the queue, calculate the bonus field and set it for each Employee object and display the object status: first name, last name, pay and bonus for each employee.

Also your program should calculate and display the number of the employees in the company and the total bonus that the company will pay for all its employees.

Make sure you break up your code into a set of well-defined functions. Each function should include a comment block that briefly describes it, its parameters and any return values.

John    Smith   90000
Mathew  Marshal 89000
Nicole  Lopaz   88200
Adam    Benjamin        83400
Julia   Hart    82000
Mary    Loveland        79000
Varon   Bansel  73400
Ali     Hassan  63000
Joseph  Murty   52000
Ryan    Frankel 43400
Julianne        Johnson 38600
Noah    Expo    22000
Deven   Williams        19300
Richard Peal    15200
Lee     Wang    14300

in python

Solutions

Expert Solution

Program

# to use queue import module queue

import queue

# employee class defintion

class Employee:

    def __init__(self,firstName,lastName,annualSalary):

        self.firstName=firstName

        self.lastName=lastName

        self.annualSalary=annualSalary

        self.bonus=0

    # set bonus function

    def setBonus(self,bonus):

        self.bonus=bonus

    # get bonus function

    def getBonus(self):

        return self.bonus

def fillQueuefromFile():

    # fillQueuefromFile function

    # takes not input

    # returns queue of employees loaded from dirany file

    employeeQueue=queue.Queue()

    # initialize queue and open dirany.txt file

    file=open("dirany.txt")

    # read line by line until end of file

    line=file.readline()

    while(line):

        # split the line according to tabs

        tokens=line.split("\t")

        # add to queue an employee object

        employeeQueue.put(Employee(tokens[0],tokens[1],tokens[2][:-1]))

        line=file.readline()

    return employeeQueue

def calculateBonus(employeeQ):

    # calculate bonus function

    # takes input an employee queue

    # returns total bonus paid and the number of employees in queue

    bonus=20    

    # initial bonus

    totalBonusAmt=0

    size=0

    # headers

    print("%10s"%("FirstName"),"%10s"%("\tLastName"),"%10s"%("\t\tPay"),"%10s"%("\tBonus"))

    # loop until the queue is empty

    while not employeeQ.empty():

        emp=employeeQ.get()

        # increment the count for each employee deleted from queue

        size=size+1

        # bonus calculation

        bonusAmt=float(emp.annualSalary)+(float(emp.annualSalary)*(bonus/100))

        # add the bonus to total bonus amount

        totalBonusAmt=totalBonusAmt+bonusAmt

        emp.setBonus(bonusAmt)

        # print the record with formatting

        print("%10s"%(emp.firstName)+"\t"

            +"%10s"%(emp.lastName)+"\t"

            +"%10s"%(str(emp.annualSalary))+"\t"

            +"%10s"%(str(emp.bonus)))

        # bonus can't be negative

        if bonus>0:

            bonus=bonus-1

    return totalBonusAmt,size

# main function calls all other functions

def main():

    employeeQ=fillQueuefromFile()

    totalBonus,size=calculateBonus(employeeQ)

    # print number of employees and total bonus paid

    print("Number of Employees are "+str(size))

    print("Total Bonus paid by company is "+str(totalBonus))

if __name__ == '__main__':

    main()

refer to below screenshots for indentation and output

Output


Related Solutions

The observed genotype frequencies will be posted on blackboard as an announcement during class.
  Part 3 – Calculating allele frequency changes and Hardy-Weinberg proportions The observed genotype frequencies will be posted on blackboard as an announcement during class. The excel-based Hardy-Weinberg calculator (HWE.xls) will be helpful for filling out the table below. Focus on the dark colour soil population and calculate allele frequencies, frequencies of heterozygous individuals, etc. Simulation step #DD #Dd #dd Observed frequency of D allele Observed frequency of Dd individuals Expected frequency of Dd (assuming HWE) Chi-squared value* Starting conditions...
Write in Java Modify the parent class (Plant) by adding the following abstract methods:(The class give...
Write in Java Modify the parent class (Plant) by adding the following abstract methods:(The class give in the end of question) a method to return the botanical (Latin) name of the plant a method that describes how the plant is used by humans (as food, to build houses, etc) Add a Vegetable class with a flavor variable (sweet, salty, tart, etc) and 2 methods that return the following information: list 2 dishes (meals) that the vegetable can be used in...
JAVA- Modify the LinkedList1 class presented in this chapter by adding sort() and reverse() methods. The...
JAVA- Modify the LinkedList1 class presented in this chapter by adding sort() and reverse() methods. The reverse method reverses the order of the elements in the list, and the sort method rearranges the elements in the list so they are sorted in alphabetical order. The class should use recursion to implement the sort and reverse operations. Extend the graphical interface in the LinkedList1Demo class to support sort and reverse commands, and use it to test the new methods. LinkedList1: class...
Modify StudentLinkedList class by adding the following methods: printStudentList: print by calling and printing “toString” of...
Modify StudentLinkedList class by adding the following methods: printStudentList: print by calling and printing “toString” of every object in the linkedList. Every student object to be printed in a separate line.  deleteStudentByID(long id): delete student object from the list whose ID is matching with the passed parameter.  sortListByID(): sort the linkedlist according to students IDs.  findMarksAverage(): find the average of all marks for all students in the list.  findMinMark(int markIndex): find the student with the minimum...
Problem 3: Modify StudentLinkedList class by adding the following methods:  printStudentList: print by calling and...
Problem 3: Modify StudentLinkedList class by adding the following methods:  printStudentList: print by calling and printing “toString” of every object in the linkedList. Every student object to be printed in a separate line.  deleteStudentByID(long id): delete student object from the list whose ID is matching with the passed parameter.  sortListByID(): sort the linkedlist according to students IDs.  findMarksAverage(): find the average of all marks for all students in the list.  findMinMark(int markIndex): find the student...
Using Java create a program that does the following: Modify the LinkedList1 class by adding sort()...
Using Java create a program that does the following: Modify the LinkedList1 class by adding sort() and reverse() methods. The reverse method reverses the order of the elements in the list, and the sort method rearranges the elements in the list so they are sorted in alphabetical order. Do not use recursion to implement either of these operations. Extend the graphical interface in the LinkedList1Demo class to support sort and reverse commands, and use it to test the new methods....
Instructions Modify the Product class from the Practice Exercise 7 by adding a quantity member. Include...
Instructions Modify the Product class from the Practice Exercise 7 by adding a quantity member. Include a getter and setter, using decorators, and modify the appropriate constructor to also accept a quantity parameter. Then modify the inventory.py file from the practice exercise to include quantity values in the constructor calls with a quantity of 100 for product1 (hammers) and 3000 for product2 (nails). Add print statements to display the quantity values as shown in the Expected Output included below. Submission...
2.     Modify assignment 1 solution code I posted to do the following: a.     Change car class to bankAccount...
2.     Modify assignment 1 solution code I posted to do the following: a.     Change car class to bankAccount class and TestCar class to TestBank class b.     Change mileage to balance c.     Change car info (make, model, color, year, fuel efficiency) to customer first and last name and account balance d.     Change add gas to deposit (without limit) e.     Change drive to withdraw cash f.  Change test car menu to the following Bank Account Menu choices 1 - Deposit 2 - Withdraw 3 - Display account info 4...
Modify the supplied payroll system to include a private instance variable called joinDate in class Employee...
Modify the supplied payroll system to include a private instance variable called joinDate in class Employee to represent when they joined the company. Use the Joda-Time library class LocalDate as the type for this variable. See http://www.joda.org/joda-time/index.html for details end examples of how to use this library. You may also have to download the Joda-Time library (JAR File) and include this in your CLASSPATH or IDE Project Libraries. Use a static variable in the Employee class to help automatically assign...
Part I: The Employee Class You are to first update the Employee class to include two virtual functions. This will make the Employee class an abstract class.
  Part I:   The Employee Class You are to first update the Employee class to include two virtual functions. This will make the Employee class an abstract class. * Update the function display() to be a virtual function     * Add function, double weeklyEarning() to be a pure virtual function. This will make Employee an abstract class, so your main will not be able to create any Employee objects. Part II: The Derived Classes Add an weeklyEarning() function to each...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT