protocol Building {
var rooms: Int { get }
var cost: Int { get }
var agent: String { get }
func salesSummary()
}
extension Building {
func salesSummary() {
print("""
SUMMARY
Building Type: \(Self.self)
Rooms: \(rooms)
Cost: \(cost)
Agent: \(agent)
\n
""")
}
}
struct House: Building {
var rooms: Int
var cost: Int
var agent: String
}
struct Office: Building {
var rooms: Int
var cost: Int
var agent: String
}
let house = House(rooms: 6, cost: 150_000, agent: "Jenna")
house.salesSummary()
let office = Office(rooms: 2, cost: 50_000, agent: "Gianna")
office.salesSummary()
let extHouse = House(rooms: 5, cost: 250_000, agent: "Robert")
extHouse.salesSummary()
No comments:
Post a Comment