Skip to content

Commit

Permalink
Day 15 commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tbrlpld committed Apr 22, 2023
1 parent 66282de commit 074819f
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 0 deletions.
Binary file not shown.
53 changes: 53 additions & 0 deletions checkpoint-8.playground/Contents.swift
@@ -0,0 +1,53 @@
import Cocoa

// Your challenge is this: make a protocol that describes a building, adding various properties and methods, then create two structs, House and Office, that conform to it. Your protocol should require the following:
//
// A property storing how many rooms it has.
// A property storing the cost as an integer (e.g. 500,000 for a building costing $500,000.)
// A property storing the name of the estate agent responsible for selling the building.
// A method for printing the sales summary of the building, describing what it is along with its other properties.


protocol Building {
var numberOfRooms: Int { get }
var cost: Int { get set }
var agent: String { get set }

func salesSummary()
}


struct House: Building {
let numberOfRooms: Int
var cost: Int
var agent: String

func salesSummary() {
print("This is a house.")
print("It has \( self.numberOfRooms ) bedrooms.")
print("You can buy it from \( agent ) for $\( cost )")
}
}


struct Office: Building {
let numberOfRooms: Int
var cost: Int
var agent: String

func salesSummary() {
print("This is an office building.")
print("It has an open floor plan with space for \( self.numberOfRooms ) offices.")
print("Contact \( agent ) for pricing details.")
}
}



let home = House(numberOfRooms: 3, cost: 800_000, agent: "BayView Realtors")
home.salesSummary()

print()

let loft = Office(numberOfRooms: 20, cost: 8_000_000, agent: "Enterprise Sales")
loft.salesSummary()
4 changes: 4 additions & 0 deletions checkpoint-8.playground/contents.xcplayground
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='macos' buildActiveScheme='true' importAppTypes='true'>
<timeline fileName='timeline.xctimeline'/>
</playground>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
67 changes: 67 additions & 0 deletions day-13.playground/Contents.swift
@@ -0,0 +1,67 @@
import Cocoa

protocol Vehicle {
func estimateTime(for distance: Int) -> Int
func travel(distance: Int)
}

struct Car: Vehicle {
func estimateTime(for distance: Int) -> Int {
distance / 50
}

func travel(distance: Int) {
print("I'm driving \(distance)km.")
}

func openSunroof() {
print("It's a nice day!")
}
}


let twopointzero = 2.0
let two = 2
twopointzero == twopointzero
two == two
// This does not work, because of the different types.
//two == twopointzero


func trim(_ string: String) -> String {
return string.trimmingCharacters(in: .whitespacesAndNewlines)
}

extension String {
func trimmed() -> String {
return self.trimmingCharacters(in: .whitespacesAndNewlines)
}

mutating func trim() -> Void {
self = self.trimmed()
}
}

let quote = " There is whitespace around. "

quote.trimmed()
quote

var otherQuote = " There is also whitespace here "
otherQuote.trim()
otherQuote


protocol SuperHeroMovie {
func writeScript() -> String
}
extension SuperHeroMovie {
func makeScript() -> String {
return """
Lots of special effects,
some half-baked jokes,
and a hint of another
sequel at the end.
"""
}
}
4 changes: 4 additions & 0 deletions day-13.playground/contents.xcplayground
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='macos' buildActiveScheme='true' importAppTypes='true'>
<timeline fileName='timeline.xctimeline'/>
</playground>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

0 comments on commit 074819f

Please sign in to comment.