Samorokimetal

Recipe 19.11.2020

Nov 22nd, 2020 (edited)
436
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Recipe {
  2.     private String name;
  3.     private String[] ingredients;
  4.     int steps;
  5.     int minutes;
  6.     int hours;
  7.     double price;
  8.  
  9.     public Recipe (String name, String[] ingredients, int steps, int minutes, double price) {
  10.         this.setName(name);
  11.         this.setIngredients(ingredients);
  12.         this.setSteps(steps);
  13.         this.setHours(minutes / 60);
  14.         this.setMinutes(minutes % 60);
  15.         this.setPrice(price);
  16.     }
  17.  
  18.     public String getName() {
  19.         return name;
  20.     }
  21.  
  22.     public void setName(String name) {
  23.         this.name = name;
  24.     }
  25.  
  26.     public String[] getIngredients() {
  27.         return ingredients;
  28.     }
  29.  
  30.     public void setIngredients(String[] ingredients) {
  31.         this.ingredients = ingredients;
  32.     }
  33.  
  34.     public int getSteps() {
  35.         return steps;
  36.     }
  37.  
  38.     public void setSteps(int steps) {
  39.         if (steps > 0) {
  40.             this.steps = steps;
  41.         }
  42.     }
  43.  
  44.     public int getMinutes() {
  45.         return minutes;
  46.     }
  47.  
  48.     public void setMinutes(int minutes) {
  49.         if (minutes >= 0) {
  50.             this.minutes = minutes;
  51.         }
  52.     }
  53.  
  54.     public int getHours() {
  55.         return hours;
  56.     }
  57.  
  58.     public void setHours(int hours) {
  59.         if (hours >= 0) {
  60.             this.hours = hours;
  61.         }
  62.     }
  63.  
  64.     public int timeInMinutes() {
  65.         int timeInMins = this.hours * 60 + this.minutes;
  66.         return timeInMins;
  67.     }
  68.  
  69.     public double getPrice() {
  70.         return price;
  71.     }
  72.  
  73.     public void setPrice(double price) {
  74.         if (price >= 0) {
  75.             this.price = price;
  76.         }
  77.     }
  78.  
  79.     @Override
  80.     public String toString() {
  81.         String time = String.format("%d:%02d", this.hours, this.minutes);
  82.         return "[Name: " + this.name +
  83.                 ", ingredients: " + this.ingredients +
  84.                 ", steps: " + this.steps +
  85.                 ", time: " + time +
  86.                 ", price: " + this.price + "]";
  87.     }
  88. }
RAW Paste Data