SHARE
TWEET

Untitled

a guest Jan 22nd, 2020 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package healthyHeaven;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. public class Restaurant {
  7.     private List<Salad> data;
  8.     private String name;
  9.  
  10.  
  11.     public Restaurant(String name){
  12.         this.name = name;
  13.         data = new ArrayList<>();
  14.     }
  15.  
  16.     public void add(Salad salad){
  17.         data.add(salad);
  18.     }
  19.  
  20.     public boolean buy(String name){
  21.         boolean check = false;
  22.  
  23.         for (int i = 0; i <data.size() ; i++) {
  24.             Salad salad = data.get(i);
  25.             if(salad.getName().equals(name)){
  26.                 check = true;
  27.                 data.remove(i);
  28.                 break;
  29.             }
  30.         }
  31.         return check;
  32.     }
  33.  
  34.     public Salad getHealthiestSalad(){
  35.         Salad salad = null;
  36.         int value = Integer.MAX_VALUE;
  37.  
  38.         for (Salad current : data) {
  39.             if(current.getTotalCalories()<value){
  40.                 salad = current;
  41.             }
  42.         }
  43.         return salad;
  44.     }
  45.  
  46.     public String generateMenu() {
  47.  
  48.         StringBuilder sb = new StringBuilder();
  49.  
  50.         sb.append(String.format("%s have %d salads:",this.name,data.size()));
  51.         sb.append(System.lineSeparator());
  52.  
  53.         for (Salad currentSalad : data) {
  54.             sb.append(currentSalad.toString());
  55.             sb.append(System.lineSeparator());
  56.         }
  57.         return sb.toString().trim();
  58.     }
  59. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top