Home > Software design >  Big Decimal in Java
Big Decimal in Java

Time:09-01

As trainee in Java I need to find how to reduce the value of a BigDecimal variable with the value of a Map, thats also BigDecimal.. OK, for example: I have a restaurant with wareHose where I save my productAvailabilities and a menuMap, where I create my products, SO: when I have an order (Pizza), I have to reduce the available quantity from the wareHouse, with the quantities I need for create my order. Every single Pizza has its map : Map<Product.Type, Quantity> pizza

CodePudding user response:

If you want to update value of Quantity, then you can use put method

pizza.put(key, val);

to add a new key/value pair or overwrite an existing key's value.

CodePudding user response:

class Recipe:
    pizza.put(Product.Type.CHEDDAR, new Quantity(BigDecimal.valueOf(40), Quantity.Unit.G));
        pizza.put(Product.Type.ONION, new Quantity(BigDecimal.valueOf(20), Quantity.Unit.G));
        pizzaList.add(new Pizza(Pizza.PizzaType.CLASSIC, Pizza.PizzaSize.LARGE, pizza));

class WareHouse :

     foodQuantities.put(Product.Type.ONION, new Product(Product.Type.ONION, BigDecimal.valueOf(5)));
        foodQuantities.put(Product.Type.CHEDDAR, new Product(Product.Type.CHEDDAR, BigDecimal.valueOf(5)));

class Chef:
//The chef cooks, so he reduce the available quantity from ware house by using the neededIngredients from the Recipe.

avilableProducts.computeIfPresent(Product.Type.TOMATO, (k, v) -> v - 0.100);
            avilableProducts.computeIfPresent(Product.Type.CUCUMBER, (k, v) -> v - 0.100);
  • Related