Advertisement
Akito13

BaseHamburger

Dec 8th, 2017
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.68 KB | None | 0 0
  1. /**
  2.  * Base Class working mainly as Superclass to special burgers of other classes which extend to this base class.
  3.  */
  4.  
  5. /**
  6.  * @author Akito
  7.  *
  8.  */
  9. public class BaseHamburger {
  10.  
  11.     private char breadRollType;
  12.     private boolean hasMeat;
  13.     private double price;
  14.    
  15.     /**
  16.      * @param breadRollType
  17.      * @param hasMeat
  18.      * @param price
  19.      *
  20.      * Superconstructor as base construct to children burgers.
  21.      */
  22.     public BaseHamburger(char breadRollType, boolean hasMeat, double price) {
  23.         super();
  24.         this.breadRollType = breadRollType;
  25.         this.hasMeat = hasMeat;
  26.         this.price = price;
  27.     }
  28.    
  29.     private String ingredient;
  30.    
  31.     /**
  32.      * @param ingredient the ingredient to set
  33.      * Setting ingredient and calling the addition of the chosen ingredient.
  34.      */
  35.     public void setIngredient(String ingredient) {
  36.         this.ingredient = ingredient;
  37.         if (ingredient.replace("s", "").toLowerCase().equals("tomato") || ingredient.replace("s", "").toLowerCase().equals("lettuce") || ingredient.replace("s", "").toLowerCase().equals("pickle")) {
  38.             System.out.println(ingredient + " added!");
  39.             addIngredient(ingredient);
  40.         }
  41.         else
  42.             System.out.println("Adding ingredient failed. Please select one of the correct ingredients!");
  43.         }
  44.    
  45.     /*
  46.      * Actually adding ingredient to burger and increasing total price on order.
  47.      * Called by ingredient Setter.
  48.      */
  49.     private void addIngredient(String ingredient) {
  50.         switch (ingredient.replace("s", "").toLowerCase()) {
  51.             case "tomato":
  52.                 System.out.println("Added " + ingredient);
  53.                 break;
  54.             case "lettuce":
  55.                 System.out.println("Added " + ingredient);
  56.                 break;
  57.             case "pickle":
  58.                 System.out.println("Added " + ingredient);
  59.                 break;
  60.         }
  61.    
  62.     }
  63.    
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement