FastPrepREST API: Discounted Price
Problem · Design

REST API: Discounted Price

Learn this problem
EasyOracle logoOracleFULLTIMEOA

Problem statement

Given a barcode, query the API at https://jsonmock.hackerrank.com/api/inventory?barcode=barcode and return the item's discounted price.

The response is a JSON object with 5 fields. The essential field is data:

  • data: Either an empty array or an array with a single object that contains the item's record.

In the data array, the item has the following schema:

  • barcode: the barcode for the product (String)
  • price: the gross selling price (Number)
  • discount: the discount percent to apply (Number).
  • Some fields that are not of interest.

page, per_page, total, total_pages, etc. are not required for this task.

If the barcode is found, the data array contains exactly 1 element. If not, it is empty and the function should return '-1'.

Use the "discount" and the "price" properties to calculate the discounted price rounded to the nearest integer.

discountedPrice = price - ((discount / 100) * price)

Function Description Complete the function getDiscountedPrice in the editor. getDiscountedPrice has the following parameters:

  • string barcode: the item to query

Returns int: the discounted price rounded to the nearest integer or -1

Function

getDiscountedPrice(barcode: String) → int

Examples

Example 1

barcode = "74002314"return = 2964

First, a call is made to API https://jsonmock.hackerrank.com/api/inventory?barcode=74002314. The price = 3705 and discount = 20.

Constraints

  • There will be either 1 or 0 records in data.

More Oracle problems

drafts saved locally
public int getDiscountedPrice(String barcode) {
    // write your code here
}
barcode"74002314"
expected2964
checking account