What are we supposed to do with this task?
Adding it to an ArrayList. Is that what is meant by changing the state of an object?
I googled it but could not find an explanation of what it means in this context.
Can someone please enlighten me?
I have no idea what is meant by changing the state of an object?
Resolved
Comments (6)
- Popular
- New
- Old
You must be signed in to leave a comment
Henry
20 February 2020, 20:59
Can you post the task here?.
0
Liliane Top
21 February 2020, 06:09
GoodMorning Henri, I guess for you it is still night.
The task description is as follows:
Once there were five classes: red riding hood, grandmother, pie, woodcutter, and wolf.
2. Each class has 2 fields: ArrayList killed and ArrayList ate.
3. The necessary objects have been created (hood, grandmother, ...).
4. Arrange the relationships correctly according to who ate and/or killed who in the fairy tale "Little Red Riding Hood".
PS: Nobody ate the pie. It was only carried in a basket. The wolf ate a little. And then he was killed.
0
Liliane Top
21 February 2020, 06:11
These are the Requirements:
• The main method should change the state (internal variables) of the wolf object.
• The main method should change the state (internal variables) of the woodcutter object.
• Nobody ate the pie.
• The wolf ate a little.
• And then the wolf was killed.
0
Liliane Top
21 February 2020, 06:15
I googled what changing state of an object means:
State in Java. State is a behavioral design pattern that allows an object to change the behavior when its internal state changes. The pattern extracts state-related behaviors into separate state classes and forces the original object to delegate the work to an instance of these classes, instead of acting on its own.
This makes no sense to me
0
jamylam
21 February 2020, 14:39useful
class Pet{
String name; // state
public void Sound(){
//behaviour
}
}
so assuming we have two classes Dog and Cat which inherits Pet. When its Dog(String name = "dog"), the behaviour (Sound) will change to bark and when its Cat the behaviour will change to Meaw.
So basically i understand that is what changing state of an object means. The methods change based on the internal state , given by the definition you have provided.
in the task as an example
wolf.ate.add(pie)
ridinghood.ate.add(wolf)
wolf and ridinghood both are changing their state in the main method. As opposed to its original state in the StoryItem class where it inheriting the state from.
+1
Liliane Top
21 February 2020, 16:23
Wauh thanks so much for taking the time to explain this to me. It makes more sense now. Very much appreciated!
0