Advertisement
Guest User

1233

a guest
Feb 19th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. public class Menu {
  2. private Dish[] dishes;
  3. public static final int MAX = 10;
  4. public int numDish;
  5.  
  6. public Menu() {
  7. dishes = new Dish[MAX];
  8. numDish = 0;
  9. }
  10. public void addDish(String name, double cost) {
  11. if (numDish < MAX) {
  12. dishes[numDish] = new Dish(name, cost);
  13. numDish++;
  14. }
  15. else {
  16. System.out.println("Menu is full.");
  17. }
  18. }
  19. public Dish findDish(String name) {
  20. int i;
  21. Dish temp;
  22. for(i = 0; i < numDish; i++) {
  23. if (dishes[i].equals(name))
  24. return dishes[i];
  25. }
  26. return null;
  27. }
  28. public double getPrice(String name) {
  29. Dish temp = findDish(name);
  30. if (temp != null) {
  31. return temp.getPrice();
  32. } else {
  33. return 0;
  34. }
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement