jeudi 15 février 2018

Random values from map sum of which is less or equal

I have a class Breakfast and method eat() where I receive BMR and can calculate calories for breakfast. I have map, where we can see food and it's calories. I want to return a menu which consists of random food from map, but sum of these random food calories should be <= caloriesForBreafast. Could you please help me how can I implement it? Thank u!

public class Breakfast implements Meal {

    @Override
    public void eat(int BMR) {

        int caloriesForBreakfast;
        caloriesForBreakfast = (int) (BMR*0.25);
        System.out.println("caloriesForBreakfast: " +  caloriesForBreakfast);

        Map<String, Integer> foodForBreakfast = new HashMap();

        foodForBreakfast.put("oatmeal", 356);
        foodForBreakfast.put("egg",150);
        foodForBreakfast.put("curd", 233);
        foodForBreakfast.put("bun", 240);
        foodForBreakfast.put("banana", 95);
        foodForBreakfast.put("sandwich", 340);
        foodForBreakfast.put("milk", 62);
}




Aucun commentaire:

Enregistrer un commentaire