• Post Reply Bookmark Topic Watch Topic
  • New Topic

Get and Set methods for an instantiated object?  RSS feed

 
Michaell Sam
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, so let's say I am being told to (assignment) create a new Bread Object in another class than the original. But after that it is asking for get and set methods. Get and set methods of what? It's parameters?

This is my Bread class.



This is the Sandwich Class in which I create a new bread object, my next instructions are to create get and set methods but I have no idea what to get or set...



Like I don't even get what I'm supposed to do. Any and all help would be appreciated!
 
Knute Snortum
Sheriff
Posts: 4279
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

I would suppose you should write getters and setters for sandwichName and sandwichPrice in class Sandwich.
 
Michaell Sam
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, I did that, I just deleted it from the post because it wasn't needed for my question regarding the instantiated bread object. Thanks for the answer though, Knute!
 
Knute Snortum
Sheriff
Posts: 4279
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you still have a question? I guess I'm missing it.
 
Michaell Sam
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup, the exact instructions I was gives are "Create a field to hold a Bread object. When creating the field, declare and then initialize it by creating a new Bread object. Create get and set methods." I have no idea what that last part wants me to do, as in what am I supposed to be getting and setting? Later on in the class I am also supposed to create a constructor that accepts all the attributes of a sandwhich such as bread type, filling, name, calories, and such if that helps any, I am stuck without a clue on what to set and get. The only thing I can think of is its parameters, such as String breadType, and int numberOfCaloriesPerSlice. But I'm not sure how I would go about that.
 
Knute Snortum
Sheriff
Posts: 4279
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It isn't clear to me what you're supposed to be getting and setting either -- if it's not the fields I mentioned above. I would ask your instructor what she or he meant.
 
Junilu Lacar
Sheriff
Posts: 11490
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Poorly worded instructions but this is not unlike a lot of real-world requirements. Ambiguous requirements are par for the course when you develop software so get used to it. I would assume based on proximity that "create getters and setters" implies "for the private bread field/attribute" but then again, as with real-world requirements, you have to go back to the source and have a conversation if you want to be sure.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!