Advertisement
xickoh

Untitled

Apr 14th, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. no demo:
  2.  
  3. public static void listIngredients(Pizza pizza) {
  4.  
  5. String name;
  6. Scanner scanIn = new Scanner(System.in);
  7. System.out.println("Digite o nome da pizza");
  8. name = scanIn.nextLine();
  9.  
  10. String[] ingList = pizza.getIngredients(name);
  11. for (String ingName : ingList) {
  12. if (ingName != null) {
  13. System.out.println(ingName);
  14. }
  15. }
  16.  
  17. // Ingredients[] ing = null;
  18. }
  19.  
  20.  
  21. na classe Pizza
  22.  
  23. public String[] getIngredients(String name) {
  24. int j = this.numberOfIngredients;
  25. String[] ingredientsName = new String[j];
  26.  
  27. //Estava aqui
  28. for (int i = 0; i < j; i++) {
  29. if (ingredients[i] != null) {
  30. if (name.equals(this.name)) {
  31. ingredientsName[i] = ingredients[i].getName();
  32. }
  33. }
  34. }
  35. return ingredientsName;
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement