Guest User

Untitled

a guest
Jul 8th, 2020
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.21 KB | None | 0 0
  1. package restaurant;
  2.  
  3. import java.math.BigDecimal;
  4.  
  5. public class Beverage extends Product {
  6. private double milliliters;
  7.  
  8. public Beverage(String name, BigDecimal price, double milliliters) {
  9. super(name, price);
  10. this.milliliters=milliliters;
  11. }
  12.  
  13. public double getMilliliters() {
  14. return milliliters;
  15. }
  16. }
  17. //=======================================================================================================
  18. package restaurant;
  19.  
  20. import java.math.BigDecimal;
  21.  
  22. public class ColdBeverage extends Beverage{
  23. public ColdBeverage(String name, BigDecimal price, double milliliters) {
  24. super(name, price, milliliters);
  25. }
  26. }
  27. //=======================================================================================================
  28. package restaurant;
  29.  
  30. import java.math.BigDecimal;
  31.  
  32. public class HotBeverage extends Beverage{
  33. public HotBeverage(String name, BigDecimal price, double milliliters) {
  34. super(name, price, milliliters);
  35. }
  36. }
  37. //=======================================================================================================
  38. package restaurant;
  39.  
  40. import java.math.BigDecimal;
  41.  
  42. public class Coffee extends HotBeverage {
  43. private static final double COFFEE_MILLILITERS = 50.0;
  44. private static final BigDecimal COFFEE_PRICE = BigDecimal.valueOf(3.50);
  45. private double caffeine;
  46.  
  47. public Coffee(String name, BigDecimal price, double milliliters) {
  48. super(name, price, milliliters);
  49. }
  50.  
  51. public double getCaffeine() {
  52. return caffeine;
  53. }
  54. }
  55. //=======================================================================================================
  56. package restaurant;
  57.  
  58. import java.math.BigDecimal;
  59.  
  60. public class Tea extends HotBeverage {
  61. public Tea(String name, BigDecimal price, double milliliters) {
  62. super(name, price, milliliters);
  63. }
  64. }
  65. //=======================================================================================================
  66. package restaurant;
  67.  
  68. import java.math.BigDecimal;
  69.  
  70. public class Food extends Product{
  71. private double grams;
  72.  
  73. public Food(String name, BigDecimal price, double grams) {
  74. super(name, price);
  75. this.grams = grams;
  76. }
  77.  
  78. public double getGrams() {
  79. return grams;
  80. }
  81. }
  82. //=======================================================================================================
  83. package restaurant;
  84.  
  85. import java.math.BigDecimal;
  86.  
  87. public class MainDish extends Food {
  88.  
  89. public MainDish(String name, BigDecimal price, double grams) {
  90. super(name, price, grams);
  91. }
  92. }
  93. //=======================================================================================================
  94. package restaurant;
  95.  
  96. import java.math.BigDecimal;
  97.  
  98. public class Starter extends Food{
  99. public Starter(String name, BigDecimal price, double grams) {
  100. super(name, price, grams);
  101. }
  102. }
  103. //=======================================================================================================
  104. package restaurant;
  105.  
  106. import java.math.BigDecimal;
  107.  
  108. public class Dessert extends Food{
  109. private double calories;
  110. public Dessert(String name, BigDecimal price, double grams, double calories) {
  111. super(name, price, grams);
  112. this.calories = calories;
  113. }
  114.  
  115. public double getCalories() {
  116. return calories;
  117. }
  118. }
  119. //=======================================================================================================
  120. package restaurant;
  121.  
  122. import java.math.BigDecimal;
  123.  
  124. public class Soup extends Starter {
  125. public Soup(String name, BigDecimal price, double grams) {
  126. super(name, price, grams);
  127. }
  128. }
  129. //=======================================================================================================
  130. package restaurant;
  131.  
  132. import java.math.BigDecimal;
  133.  
  134. public class Dessert extends Food{
  135. private double calories;
  136. public Dessert(String name, BigDecimal price, double grams, double calories) {
  137. super(name, price, grams);
  138. this.calories = calories;
  139. }
  140.  
  141. public double getCalories() {
  142. return calories;
  143. }
  144. }
  145. //=======================================================================================================
  146. package restaurant;
  147.  
  148. import java.math.BigDecimal;
  149.  
  150. public class Salmon extends MainDish {
  151. private final static double SALMON_GRAMS = 22.0;
  152. public Salmon(String name, BigDecimal price, double grams) {
  153. super(name, price, grams);
  154. }
  155. }
  156. //=======================================================================================================
  157. package restaurant;
  158.  
  159. import java.math.BigDecimal;
  160.  
  161. public class Product {
  162. private String name;
  163. private BigDecimal price;
  164.  
  165. public Product(String name, BigDecimal price) {
  166. this.setName(name);
  167. this.setPrice(price);
  168. }
  169.  
  170. private void setPrice(BigDecimal price) {
  171. if (this.price ==null){
  172. this.price = price;
  173. }
  174. }
  175.  
  176. private void setName(String name) {
  177. if (this.name == null){
  178. this.name = name;
  179. }
  180. }
  181.  
  182. public String getName() {
  183. return name;
  184. }
  185.  
  186. public BigDecimal getPrice() {
  187. return price;
  188. }
  189.  
  190. }
Add Comment
Please, Sign In to add comment