nancyelsh / TASK-JS-Classes-Bareed

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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>/JSFoundations-Classes.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.

About

License:MIT License


Languages

Language:JavaScript 100.0%