Skip to content

Commit

Permalink
[#1] STEP 1. Fist Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Wody95 committed Mar 8, 2021
1 parent a02ced5 commit 594a770
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 5 deletions.
1 change: 1 addition & 0 deletions JuiceMaker/JuiceMaker/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}



}

18 changes: 13 additions & 5 deletions JuiceMaker/JuiceMaker/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17703"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="JuiceMaker" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-259" y="117"/>
</scene>
</scenes>
<resources>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
</resources>
</document>
114 changes: 114 additions & 0 deletions JuiceMaker/JuiceMaker/JuiceMaker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,118 @@

import Foundation


/// 쥬스 메이커 타입
class Fruit {
var fruitName: String = ""
var fruitCount: Int = 10
}

class Juice {
var juiceName: String = ""
var juiceRecipe: [String: Int] = [:]
}


class JuiceMaker {
var fruitNames: [String] = ["딸기", "바나나", "파인애플", "키위", "망고"]
var juiceNames: [String] = ["딸기쥬스", "바나나쥬스", "키위쥬스", "파인애플쥬스", "딸바쥬스", "망고쥬스", "망고키위쥬스"]

func activeJuiceMaker() {
var fruits = makeBasicFruits(Names: fruitNames)
var juices = makeBaisicJuices(Names: juiceNames)

if let name = fruits["딸기"]?.fruitName {
print(name)
}

if let name = juices["딸기쥬스"]?.juiceName {
print(name)
}
if let recipe = juices["바나나쥬스"]?.juiceRecipe {
print(recipe)
}

juices["딸기쥬스"]?.juiceRecipe = ["딸기": 16]
print(readJuiceRecipe(name: "딸기", juiceList: juices))

makejuice(juiceName: "딸기", juiceList: juices, fruitList: fruits)
print(readFruitInventory(name: "딸기", fruitList: fruits))
}

func readFruitInventory(name: String, fruitList: [String: Fruit]) -> Int {
var result: Int = 0
if let count = fruitList[name]?.fruitCount {
result = count
}

return result
}

func readJuiceRecipe(name: String, juiceList: [String: Juice]) -> [String: Int] {
var result: [String: Int] = [:]
if let recipe = juiceList[name]?.juiceRecipe {
result = recipe
}

return result
}

func makejuice(juiceName: String, juiceList: [String: Juice], fruitList: [String: Fruit]) {
// 1. 쥬스 이름을 통해 juices 데이터 접근
// 2. 접근한 데이터를 통해 레시피를 파악
// 3. 파악한 레시피의 과일 재고 접근
// 4. 접근한 과일 재고와 레시피를 비교
// 5. 결과
var needFruit: String = ""
var needFruitCount: Int = 0

if let recipe = juiceList[juiceName]?.juiceRecipe {
for (key, value) in recipe {
needFruit = key
needFruitCount = value

print(needFruit)
print(needFruitCount)

// 3. 레시피에 필요한 과일 재고에 접근
if let count = fruitList[key]?.fruitCount {
// 4. 과일 재고를 레시피에 필요한 양 만큼 차감
fruitList[key]?.fruitCount -= needFruitCount

print("과일 : \(key), 남은 수량 : \(count)")
}
}
}

}

func makeBasicFruits(Names: [String]) -> [String: Fruit] {
var basicFruits: [String: Fruit] = [:]

for element in Names {
let fruit = Fruit()
fruit.fruitName = element

basicFruits[element] = fruit
}

return basicFruits
}

func makeBaisicJuices(Names: [String]) -> [String: Juice] {
var basicJuices: [String: Juice] = [:]

for element in Names {
let juice = Juice()
juice.juiceName = element
juice.juiceRecipe = [:]

basicJuices[element] = juice
}

return basicJuices
}

}

4 changes: 4 additions & 0 deletions JuiceMaker/JuiceMaker/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
let testJuiceMaker = JuiceMaker()
testJuiceMaker.activeJuiceMaker()

// Do any additional setup after loading the view.
}



}

0 comments on commit 594a770

Please sign in to comment.