• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to make a method to add or not in a List  RSS feed

 
Kaique Marques
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, everyone, I am starting my studies in java, and I came across a problem that in the case would be: how to make a test not fail to add a pizza without the ingredients list CarrinhoDeCompras. And what class I would have by this method?

Note: I've been told that's pretty bad encapsulated, but not yet learned this concept well, then leave to apply after I well understand this issue.
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kaique Marques wrote:Note: I've been told that's pretty bad encapsulated, but not yet learned this concept well, then leave to apply after I well understand this issue.

My suggestion: Show us what you've written so far, and ask your question again. And don't worry if some your program is in Portugese; we're used to it.

Winston
 
Kaique Marques
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator







 
Knute Snortum
Sheriff
Posts: 4087
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When posting code, be sure to use code tags. I've done it for you this time.
 
Knute Snortum
Sheriff
Posts: 4087
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My suggestion would be to do the following:

* Make pizzas in class CarrinhoDeCompras private.

* Create a method in class CarrinhoDeCompras called addPizza(Pizza pizza).

* In this method, test whether the pizza object has ingredients and if so, add it to the List.
 
Kaique Marques
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Soo much, it works now
 
Campbell Ritchie
Marshal
Posts: 55785
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please mark all your fields private (as Knute has already told you) and don't mark any of them static. You will doubtless want ingredients for one pizza, rather than a total of ingredients for the whole shop.
Why have you got contaPizza at all? Why have you marked it static?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!