• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator







 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Soo much, it works now
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic