Code Monkey home page Code Monkey logo

jsepisode5's Introduction

JavaScript Episode 5

In this exercise we're going to design the objects for an on-demand ice cream delivery platform called Bareed.

Requirements:

The objects have the following properties and methods:

  • Point:

    • x - x coordinate.
    • y - y coordinate.
    • distanceTo(point) - takes a Point, calculates the distance to that point from the current point.
  • Wallet:

    • money - defaults to 0.
    • credit(amount) - adds amount to money.
    • debit(amount) - subtracts amount from money.
  • Person:

    • name
    • location - a Point.
    • wallet - a Wallet initially with 0.
    • moveTo(point) - moves the person to the new point.
  • Vendor:

    • name
    • location - a Point.
    • wallet - a Wallet initially with 0.
    • range - the maximum distance this vendor can travel - initially 5.
    • price - the cost of a single ice cream - initially 1.
    • moveTo(point) - moves the customer to the new point.
    • sellTo(customer, numberOfIceCreams) - sells a specific number of ice creams to customer by doing the following:
      • Move to the customer's location.
      • Transfer money from the customer's wallet to the vendor's wallet.
        NOTE: You might have to partially build the Customer class first before you can get this to work!
  • Customer:

    • name
    • location - a Point.
    • wallet - a Wallet initially with 10.
    • moveTo(point) - moves the customer to the new point.
    • _isInRange(vendor) - checks if the customer is in range of vendor.
    • _haveEnoughMoney(vendor, numberOfIceCreams) - checks if the customer has enough money to buy a specific number of ice creams from vendor.
    • requestIceCream(vendor, numberOfIceCreams) - sends a request to vendor to buy a specific number of ice creams but ONLY IF the customer is in the vendor's range AND they have enough money to buy that much ice cream. ONLY THEN is a request sent.
      BONUS: Log a helpful message to let the customer know why they can't have ice cream.
      NOTE: You might have to partially build the Vendor class first before you can get this to work!

Example Usage

let vendorAsis = new Vendor("Asis", 10, 10); // create a new vendor named Asis at location (10,10)
let nearbyCustomer = new Customer("MishMish", 11, 11); // create a new customer named MishMish at location (11,11)
let distantCustomer = new Customer("Hamsa", 1000, 1000); // create a new customer named Hamsa at location (1000,1000)
let brokeCustomer = new Customer("Maskeen", 12, 12); // create a new customer named Maskeen at location (12,12)

brokeCustomer.wallet.money = 0; // steal all of Maskeen's money

nearbyCustomer.requestIceCream(vendorAsis, 10); // ask to buy 10 ice creams from Asis
// money was transferred from MishMish to Asis
nearbyCustomer.wallet.money; // 0 left
vendorAsis.wallet.money; // 10
// Asis moved to MishMish's location
vendorAsis.location; // { x: 11, y: 11 }

distantCustomer.requestIceCream(vendorAsis, 10); // ask to buy 10 ice creams from Asis
// no money was transferred because the request failed - Hamsa is too far away
distantCustomer.wallet.money; // 10 left
vendorAsis.wallet.money; // still only 10
// Asis didn't move
vendorAsis.location; // { x: 11, y: 11 }

brokeCustomer.requestIceCream(vendorAsis, 1); // ask to buy 1 ice creams from Asis
// no money was transferred because the request failed - Maskeen doesn't have enough money to buy even one ice cream :(
brokeCustomer.wallet.money; // 0
vendorAsis.wallet.money; // still only 10
// Asis didn't move
vendorAsis.location; // { x: 11, y: 11 }

Instructions

Tools

  • Install node:
    $ brew install node
  • Install yarn:
    $ brew install yarn --without-node

The Files

Fork this repository and clone your fork (make sure you clone it into your development directory):

$ git clone https://github.com/<your_username>/JSEpisode5.git

Inside you'll find the following:

  • bareed.js - this is the file you'll be editing
  • tests/ - this is a directory of testing files. These files check that your application has the features discussed above.
    DO NOT EDIT THIS FILE

Running The Tests

Install all the requirements:

  1. Navigate to the project root (you'll find a file called package.json there).
  2. Install the requirements using yarn install.

Run the tests:

$ yarn test

This command will run the testing file and test your pairs() function to make sure it has all the required features.

You'll know when you're done when your code passes all the tests.

jsepisode5's People

Contributors

darthhamza avatar lailalelouch avatar lailz avatar octowl avatar smokeme avatar themshary avatar

Watchers

 avatar  avatar  avatar  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.