Part I [File: Employee.swift] Create a class called Employee that has the follow
ID: 3911413 • Letter: P
Question
Part I [File: Employee.swift]
Create a class called Employee that has the following stored properties:
Class Employee should have read/write properties, initializer(s) and should conform Printable protocol.
Part II [File: Taxable.swift]
Create a protocol Taxable that declares one method called income that returns the weekly income for employees
Part III [File: SalariedEmployee.swift]
Create a class called SalariedEmployee that inherits from Employee and has the following members:
Class SalariedEmployee should have read/write property, initializer(s) and should override the description property. It should also conform the protocol Taxable.
Part IV [File: HourlyEmployee.swift]
Create a class called HourlyEmployee that inherits from Employee and has the following members:
Class HourlyEmployee should have read/write properties, initializer(s) and should override the description property. It should also conform the protocol Taxable.
Part V [File: BasePlusCommissionEmployee.swift]
Create a class called BasePlusCommissionEmployee that inherits from Employee and has the following members:
Class BasePlusCommissionEmployee should have read/write properties, initializer(s) and should override the description property. It should also conform the protocol Taxable.
Part VI [File: main.swift]
Create an array that can hold Employee objects. Populate this array with two objects of Hourly, Salaried and BasePlusCommission employee objects (6 objects in total).
Display all the objects on screen.
Sort and display the employees based on their income from low to high and from high to low.
Explanation / Answer
Part I :
Employee.swift
class employee: Printable{
var emp_id: Int
var firstName: String
var lastName: String
init(emp_id:Int,firstName: String,lastName: String){
self.emp_id = emp_id;
self.firstName = firstName;
self.lastName = lastName;
}
var description: String {
return "Meeting with (self.emp_id) in (self.firstName) at (self.lastName)"
}
}
Part II:
Taxable.swift
protocol Taxable {
var weeklyIncome: Double { get }
func income(){
return self.weeklyIncome;
}
}
PART III:
class SalariedEmployee:employee,Taxable{
var yearlyIncome: Double
init(emp_id:Int,firstName: String,lastName: String,yearlyIncome:Double){
super.init(emp_id,firstName,lastName);
self.yearlyIncome = yearlyIncome;
}
var description: String {
return "Employee with Employee_ID : (self.emp_id) has First name: (self.firstName) and Last Name: (self.lastName) and Yearly Income : (self.yearlyIncome)"
}
var weeklyIncome: Double {
return self.yearlyIncome/52;
}
}
PART IV:
class HourlyEmployee:employee,Taxable{
var hourlyRate:Double
var hoursWorked:Int
init(emp_id:Int,firstName: String,lastName: String,hourlyRate:Double,hoursWorked:Int){
super.init(emp_id,firstName,lastName);
self. hourlyRate = hourlyRate;
self.hoursWorked = hoursWorked;
}
var description: String {
return "Employee with Employee_ID : (self.emp_id) has First name: (self.firstName) and Last Name: (self.lastName) and Hourly Rate : (self.hourlyRate) & Hours Worked :(self.hoursWorked)"
}
var weeklyIncome: Double {
return self.hoursWorked * self.hourlyRate /52;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.