Put ALL your code for this question in a single module \"employee.py\" Create Pe
ID: 3570860 • Letter: P
Question
Put ALL your code for this question in a single module "employee.py"
Create Person class, Employee class, OfficeWorker class, ProductionWorker class.
Employee is subclass of Person. OfficeWorker and ProductionWorker are subclass of
Employee class.
Person class has name, address, phone_number
Employee class has id_number
ProductionWorker class has shift_number, pay_rate
compute_pay_for_hours(hours)
OfficeWorker class has skill_type, month_salary
method compute_pay_for_weeks(weeks)
Assume that salary of office worker is for each 4 weeks.
Use the following code for main() function EXACTLY to test your code:
def main():
# Local variables
worker_name= ''
worker_id = ''
worker_shift = 0
worker_pay = 0.0
skill_type = ''
salary = 0.0
emp_type = 'P'
# Get data attributes
worker_name = input('Enter the name: ')
worker_address = input('Enter the address: ')
worker_phone = input('Enter the phone: ')
worker_id = input('Enter the ID number: ')
emp_type = input('Enter the employee type ('S' for salaried or 'H' for hourly): ')
if emp_type == 'S':
skill_type = input('Enter the skill type ('eng', 'acc', 'sales', 'mgr'): ')
salary = float(input('Enter the monthly salary: '))
worker = OfficeWorker(worker_name, worker_address, worker_phone, worker_id,
skill_type, salary)
elif emp_type == 'H':
worker_shift = int(input('Enter the shift number: '))
worker_pay = float(input('Enter the hourly pay rate: '))
worker = ProductionWorker(worker_name, worker_address, worker_phone, worker_id,
worker_shift, worker_pay)
else:
print('Invalid employee type')
return
# Create an instance of ProductionWorker
# Display information
print ('Employee information:')
print ('Name:', worker.get_name())
print ('Address:', worker.get_address())
print ('Phone:', worker.get_phone())
print ('ID number:', worker.get_id_number())
if isinstance(worker,ProductionWorker):
print ('Shift:', worker.get_shift_number())
print ('Hourly Pay Rate: $',
format(worker.get_pay_rate(), ',.2f'), sep='')
print ('Pay Amount for 5.2 hours: $',
format(worker.compute_pay_for_hours(5.2), ',.2f'), sep='')
else:
print ('Skill type:', worker.get_skill_type())
print ('Monthly Salary: $',
format(worker.get_month_salary(), ',.2f'), sep='')
print ('Pay Amount for 2.5 months: $',
format(worker.compute_pay_for_weeks(10), ',.2f'), sep='')
# Call the main function.
main()
Expected Input/Output:
Enter the name: John
Enter the address: 111 Main St, San Jose
Enter the phone: 111-333-4444
Enter the ID number: 123
Enter the employee type ('S' for salaried or 'H' for hourly): H
Enter the shift number: 1
Enter the hourly pay rate: 12
Employee information:
Name: John
Address: 111 Main St, San Jose
Phone: 111-333-4444
ID number: 123
Shift: 1
Hourly Pay Rate: $12.00
Pay Amount for 5.2 hours: $62.40
>>>
>>>
Enter the name: Tony
Enter the address: 555 Nice St, San Jose
Enter the phone: 222-445-6789
Enter the ID number: 4567
Enter the employee type ('S' for salaried or 'H' for hourly): S
Enter the skill type ('eng', 'acc', 'sales', 'mgr'): eng
Enter the monthly salary: 5000
Employee information:
Name: Tony
Address: 555 Nice St, San Jose
Phone: 222-445-6789
ID number: 4567
Skill type: engineering
Monthly Salary: $5,000.00
Pay Amount for 2.5 months: $12,500.00
>>>
Explanation / Answer
public class person
{
private String name, address, phone, email, emp_id ;
public person()
{
}
public person(String name, String address, String phone, String email, String emp_id,)
{
this.name = name;
this.address = address;
this.phone = phone;
this.email = email;
this.emp_id = emp_id;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getAddress()
{
return address;
}
public void setAddress(String address)
{
this.address = address;
}
public String getPhone()
{
return phone;
}
public void setPhone(String phone)
{
this.phone = phone;
}
public String getEmail()
{
return phone;
}
public void setEmail(String email)
{
this.email = email;
}
public String getEmp_id()
{
return emp_id;
}
public void setEmp_id(String emp_id)
{
this.emp_id = emp_id;
}
@Override
public String toString()
{
return getClass().getName() + " " + name;
}
}
public class employee extends person
{
private String office,salary;
private MyDate DATE_HIRED;
public employee()
{
}
public employee(String office, String salary, MyDate DATE_HIRED)
{
this.office = office;
this.salary = salary;
this.DATE_HIRED = DATE_HIRED;
}
public String office()
{
return office;
}
public void setOffice(String office)
{
this.office = office;
}
public String getSalary()
{
return salary;
}
public void setSalary(String salary)
{
this.salary = salary;
}
public MyDate getMyDate()
{
return DATE_HIRED;
}
}
public class OfficeWorker extends employee
{
private String office_hours, rank;
public OfficeWorker()
{
}
public OfficeWorker(String office_hours, String rank)
{
this.office_hours = office_hours;
this.rank = rank;
}
public String getOfficeHours()
{
return office_hours;
}
public void setOfficeHours(String office_hours)
{
this.office_hours = office_hours;
}
public String getRank()
{
return rank;
}
public void setRank(String rank)
{
this.rank = rank;
}
}
public class ProductionWorker extends employee
{
private String title;
public ProductionWorker()
{
}
public ProductionWorker(String title)
{
this.title = title;
}
public String getTitle()
{
return title;
}
public void setTitle(String title)
{
this.title =title;
}
}
public class test
{
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
Person person = new Person("John", "111 Main St, San Jose", "111-333-4444", "123", "johndoe@somewhere.com");
Person employee = new Employee("Tony", "555 Nice St, San Jose", "222-445-6789", "4567", tj@xyz.com");
Person officeWorker= new OfficeWorker("Jill Johnson", "999 Park Ave", "925-222-3333", "jj@abcxyz.com");
Person productionWorker = new ProductionWorker ("Jack I. Box", "21 Jump Street", "707-212-1112", "jib@jack.com");
System.out.println(person.toString() + " ");
System.out.println(employee.toString() + " ");
System.out.println(faculty.toString() + " ");
System.out.println(ProductionWorker.toString() + " ");
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.