Javascript.RU

Создать новую тему Ответ
 
Опции темы Искать в теме
  #1 (permalink)  
Старый 22.06.2018, 17:46
Новичок на форуме
Отправить личное сообщение для SomebodySomeone Посмотреть профиль Найти все сообщения от SomebodySomeone
 
Регистрация: 22.06.2018
Сообщений: 6

Список покупок.
Привет Буду очень благодарен за помощь в реализации данной таски.
1. Application overview:
Personal expenses management application that allows users to track how much money have they spent.
2. [MAJOR] Requirements:
As a result of test problem solution you should provide a
command-line application that supports following commands:
● add 2017-04-25 12 USD Jogurt — adds expense entry to the list of user expenses. Expenses for various dates could be added in any order. Command accepts following parameters:
2017-04-25 — is the date when expense occurred
12 — is an amount of money spent
USD — the currency in which expense occurred
Jogurt — is the name of product purchased
● list — shows the list of all expenses sorted by date
● clear 2017-04-25 — removes all expenses for specified date, where:
2017-04-25 — is the date for which all expenses should be
removed
● total PLN — this command should take a list of exchange rates
from http://fixer.io , calculate the total amount of money spent and present it to user in specified currency, where:
PLN — is the currency in which total amount of expenses should be presented
3. [MINOR] Requirements:
In order to get extra points for test problem solution you might
cover your source code with unit tests.
4. Application usage example:
Here is an example of normal application usage flow, for each command a corresponding output is shown:
> add 2017-04-25 2 USD Jogurt
2017-04-25
Jogurt 2 USD
>add 2017-04-25 3 EUR “French fries”
2017-04-25
Jogurt 2 USD
French Fries 3 EUR
> add 2017-04-27 4.75 EUR Beer
2017-04-25
Jogurt 2 USD
French Fries 3 EUR
2017-04-27
Beer 4.75 EUR
> add 2017-04-26 2.5 PLN Sweets
2017-04-25
Jogurt 2 USD
French Fries 3 EUR
2017-04-26
Sweets 2.5 PLN
2017-04-27
Beer 4.75 EUR
> list
2017-04-25
Jogurt 2 USD
French Fries 3 EUR
2017-04-26
Sweets 2.5 PLN
2017-04-27
Beer 4.75 EUR
> clear 2017-04-27
2017-04-25
Jogurt 2 USD
French Fries 3 EUR
2017-04-26
Sweets 2.5 PLN
> total EUR
5.42 EUR

Мой код:
class List {
constructor(date, amount, currency, product){
this._date = date;
this._amount = amount;
this._currency = currency;
this._product = product;
}

get data (){
return this._data;
}

get amount(){
return this._amount;
}

get currency (){
return this._currency;
}

get product (){
return this._product
}
}

class Result extends List {
constructor(date, amount, currency, product) {
super(date);
this._amount = amount;
this._currency = currency;
this._product = product;

}
}

const out = new Result(2017-04-25, 12, 'USD', 'Jogurt');
console.log(Result)

Последний раз редактировалось SomebodySomeone, 22.06.2018 в 22:58.
Ответить с цитированием
  #2 (permalink)  
Старый 23.06.2018, 13:55
Профессор
Отправить личное сообщение для Rise Посмотреть профиль Найти все сообщения от Rise
 
Регистрация: 07.11.2013
Сообщений: 4,662

Не знаю что за приложение нужно, но на js, прямо как описано, выглядит так:
class App {
    constructor() {
        // ...
    }
    add(date, amount, currency, product) {
        // ...
    }
    list() {
        // ...
    }
    clear(date) {
        // ...
    }
    total(currency) {
        // ...
        App.loadExchangeRates('USD', 'GBP,JPY,EUR', function (json) {
            if (json.success) {
                // json.base
                // json.rates.GBP * amountGBP = amountUSD
                // json.rates.JPY * amountJPY = amountUSD
                // json.rates.EUR * amountEUR = amountUSD
            }
        });
    }
    static loadExchangeRates(base, symbols, onLoad) {
        let url = 'https://data.fixer.io/api/latest',
            key = 'API_KEY',
        xhr = new XMLHttpRequest();
        xhr.open('GET', url + '?access_key=' + key + '&base=' + base + '&symbols=' + symbols);
        xhr.responseType = 'json';
        xhr.onload = onLoad;
        xhr.send();
    }
}


const app = new App();

app.add('2017-04-25', 2, 'USD', 'Jogurt')
// 2017-04-25
// Jogurt 2 USD

app.add('2017-04-25', 3, 'EUR', 'French fries')
// 2017-04-25
// Jogurt 2 USD
// French Fries 3 EUR

app.add('2017-04-27', 4.75, 'EUR', 'Beer')
// 2017-04-25
// Jogurt 2 USD
// French Fries 3 EUR
// 2017-04-27
// Beer 4.75 EUR

app.add('2017-04-26', 2.5, 'PLN', 'Sweets')
// 2017-04-25
// Jogurt 2 USD
// French Fries 3 EUR
// 2017-04-26
// Sweets 2.5 PLN
// 2017-04-27
// Beer 4.75 EUR

app.list()
// 2017-04-25
// Jogurt 2 USD
// French Fries 3 EUR
// 2017-04-26
// Sweets 2.5 PLN
// 2017-04-27
// Beer 4.75 EUR

app.clear('2017-04-27')
// 2017-04-25
// Jogurt 2 USD
// French Fries 3 EUR
// 2017-04-26
// Sweets 2.5 PLN

app.total('EUR')
// 5.42 EUR
Ответить с цитированием
Ответ



Опции темы Искать в теме
Искать в теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Двойной динамический список. oneplus Элементы интерфейса 17 14.08.2015 22:42
Выпадающий список без кнопок-стрелок для открытия vertmann (X)HTML/CSS 8 15.11.2013 11:43
селект переделанный под список Vasёk18 Элементы интерфейса 0 13.04.2012 23:49
Заполнить список значениями из динамически созданного выпадающего списка zhuzha Элементы интерфейса 0 17.08.2010 14:40
Как получить список пользовательских функций объекта window? Маэстро Events/DOM/Window 13 03.07.2010 13:20