Giter Site home page Giter Site logo

sample-vending-machine's Introduction

sample-vending-machine

準備

本PRをclone後、プロジェクト直下で下記を実行。

composer install

課題

1. もっとも通常のパターン

# 確認コマンド
composer test-round1

次の条件が通るように、runSimplyを修正。

// 100円が1枚、10円が2枚
$coins = [
  '100' => 1,
  '10' => 2,
];

// コーラは120円とする
$menu = 'cola';

// 購入処理
$change = Main::runSimply($coins, $menu);

echo($change); // "nochange" (おつりがない場合)
// 100円が2枚
$coins = [
  '100' => 2,
];

// コーラは120円とする
$menu = 'cola';

// 購入処理
$change = Main::runSimply($coins, $menu);

echo($change); // "50 1 10 3" (50円が1枚、10円が3枚)

2. 自動販売機の硬貨の枚数を考慮するパターン

# 確認コマンド
composer test-round2

次の条件が通るように、runを修正。

// 自動販売機がもつ硬貨の枚数の状況。50円玉が切れている
$vendingMachineCoins = [
    '500' => 999,
    '100' => 999,
    '50' => 0,
    '10' => 999,
];

// 100円が2枚
$coins = [
  '100' => 2,
];

// コーヒーは150円とする
$menu = 'coffee';

// 投入額と注文をまとめておく
$userInput = [
  "coins" => $coins,
  "menu" => $menu,
];

// 購入処理
$change = Main::run($vendingMachineCoins, $userInput);

echo($change); // "10 5" (50円を1枚返却したいが無いので、10円を5枚返却する)

linter (php-cs-fixer)

プロジェクト直下でcomposer lintを実行。src内が勝手にフォーマットされます。

sample-vending-machine's People

Contributors

a-kobori avatar sr2mg avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.