Question

In: Computer Science

Swift code import Foundation protocol TaksPerformer { func doAThing() } class Employee: TaksPerformer { let name:...

Swift code

import Foundation

protocol TaksPerformer {

func doAThing()

}

class Employee: TaksPerformer {

let name: String

var boss: Boss?

init(name: String) {

self.name = name

}

func doAThing() {

print("\(name) is doing a thing")

}

}

class Boss {

var employee: Employee

let name: String

init(name: String, employee: Employee) {

self.name = name

self.employee = employee

employee.boss = self

}

func actLikeABoss() {

employee.doAThing()

}

}

// 1)

// A) What is wrong with the current implementation of Boss and Employee, why is it wrong, and how can we demonstrate that there is an issue?

//

// B) What pattern discussed in class does the Boss - Employee relationship remind you of? Give an example of the discussed pattern.

//

// C) Create a Person class that has the following property:

// let name: String

// Now have Employee and Boss inherit from Person

//

// D) You realize that there are speciffic tasks you would like an employee to perform. All tasks look like this:

// func makeCoffe(_ name: String) {

// print("\(name) made coffe")

// }

//

// func writeReport(_ name: String) {

// print("\(name) wrote a report")

// }

// Modify Boss, Employee and TaskPerformer in a way that a Boss can be instantiated with the following constructor:

// Boss(name: "Bossman", employee: anEmployee, tasks: [makeCoffe, writeReport])

// The employee instance should perform the tasks.

Solutions

Expert Solution

Swift code


Related Solutions

TASK: Based upon the following code: import java.util.Scanner; // Import the Scanner class public class Main...
TASK: Based upon the following code: import java.util.Scanner; // Import the Scanner class public class Main {   public static void main( String[] args ) {     Scanner myInput = new Scanner(System.in); // Create a Scanner object     System.out.println("Enter (3) digits: ");     int W = myInput.nextInt();     int X = myInput.nextInt();     int Y = myInput.nextInt();      } } Use the tools described thus far to create additional code that will sort the integers in either monotonic ascending or descending order. Copy your code and...
Can someone please convert this java code to C code? import java.util.LinkedList; import java.util.List; public class...
Can someone please convert this java code to C code? import java.util.LinkedList; import java.util.List; public class Phase1 { /* Translates the MAL instruction to 1-3 TAL instructions * and returns the TAL instructions in a list * * mals: input program as a list of Instruction objects * * returns a list of TAL instructions (should be same size or longer than input list) */ public static List<Instruction> temp = new LinkedList<>(); public static List<Instruction> mal_to_tal(List<Instruction> mals) { for (int...
21. Consider the code below: [13] Employee class: class Employee { public: Employee(string theName, float thePayRate);...
21. Consider the code below: [13] Employee class: class Employee { public: Employee(string theName, float thePayRate); protected: string getName() const; float getPayRate() const; float pay(float hoursWorked) const; private: string name; float payRate; }; Definitions for some of the methods follow: Employee::Employee(string theName, float thePayRate) { name = theName; payRate = thePayRate; } float Employee::pay(float hoursWorked) const { return hoursWorked * payRate; } Manager Class: #include "employee.h" class Manager : public Employee { public: Manager(string theName, float thePayRate, bool isSalaried); protected:...
I'm getting an error for this code? it won't compile import java.util.*; import java.io.*; public class...
I'm getting an error for this code? it won't compile import java.util.*; import java.io.*; public class Qup3 implements xxxxxlist {// implements interface    // xxxxxlnk class variables    // head is a pointer to beginning of rlinked list    private node head;    // no. of elements in the list    // private int count; // xxxxxlnk class constructor    Qup3() {        head = null;        count = 0;    } // end Dersop3 class constructor   ...
Convert this pseudo code program into sentences. import java.util.ArrayList; import java.util.Collections; class Bulgarian {    public...
Convert this pseudo code program into sentences. import java.util.ArrayList; import java.util.Collections; class Bulgarian {    public static void main(String[] args)    {        max_cards=45;        arr->new ArraryList        col=1;        card=0;        left=max_cards;        do{            col->random number            row->new ArrayList;            for i=0 to i<col            {                card++                add card into row            }   ...
Convert this java code from hashmap into arraylist. import java.io.*; import java.util.*; public class Solution {...
Convert this java code from hashmap into arraylist. import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); HashMap labs = new HashMap(); while (true) { System.out.println("Choose operation : "); System.out.println("1. Create a Lab"); System.out.println("2. Modify a Lab"); System.out.println("3. Delete a Lab"); System.out.println("4. Assign a pc to a Lab"); System.out.println("5. Remove a pc from a Lab"); System.out.println("6. Quit"); int choice = sc.nextInt(); String name=sc.nextLine(); switch (choice) { case 1:...
Please add comments to this code! JAVA Code: import java.text.NumberFormat; public class Item {    private...
Please add comments to this code! JAVA Code: import java.text.NumberFormat; public class Item {    private String name;    private double price;    private int bulkQuantity;    private double bulkPrice;    /***    *    * @param name    * @param price    * @param bulkQuantity    * @param bulkPrice    */    public Item(String name, double price, int bulkQuantity, double bulkPrice) {        this.name = name;        this.price = price;        this.bulkQuantity = bulkQuantity;        this.bulkPrice = bulkPrice;   ...
Please add comments to this code! Item Class: import java.text.NumberFormat; public class Item {    private...
Please add comments to this code! Item Class: import java.text.NumberFormat; public class Item {    private String name;    private double price;    private int bulkQuantity;    private double bulkPrice;    /***    *    * @param name    * @param price    * @param bulkQuantity    * @param bulkPrice    */    public Item(String name, double price, int bulkQuantity, double bulkPrice) {        this.name = name;        this.price = price;        this.bulkQuantity = bulkQuantity;        this.bulkPrice = bulkPrice;   ...
Add code to the Account class and create a new class called BalanceComparator. import java.util.*; public...
Add code to the Account class and create a new class called BalanceComparator. import java.util.*; public final class Account implements Comparable {     private String firstName;     private String lastName;     private int accountNumber;     private double balance;     private boolean isNewAccount;     public Account(             String firstName,             String lastName,             int accountNumber,             double balance,             boolean isNewAccount     ) {         this.firstName = firstName;         this.lastName = lastName;         this.accountNumber = accountNumber;         this.balance = balance;         this.isNewAccount = isNewAccount;     }     /**      * TO DO: override equals      */     @Override     public boolean equals(Object other) {...
Using C#: Write a class named Employee that has the following properties: Name - The Name...
Using C#: Write a class named Employee that has the following properties: Name - The Name property holds the employee's name IdNumber - The IdNumber property holds the employee's ID number Department - The Department property holds the name of the department in which the employee works Position - The Position property holds the employee's job title The class should have the following overloaded constructors: A constructor that accepts the following values as arguments and assigns them to the appropriate...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT