Question: Object orientated programming in java, how to make conditional private attributes? (without setters?). FarmTest Farm Animal has-a (composition) is-a (inheritance) Chicken Cow Llama (A) the

Object orientated programming in java, how to make conditional private attributes? (without setters?).Object orientated programming in java, how to make conditional private attributes? (without

FarmTest Farm Animal has-a (composition) is-a (inheritance) Chicken Cow Llama (A) the Animal class contains: o +1 Six private attributes: . name (String) - the animal's name * energy (double) - the animal's energy level (must be from 0 to 100). * alive (boolean) - true only when energy>0 . mealAmount (double) - the maximum amount of food the animal can eat when we call its eat method (must be from 0 to 100) * x and y (double) - the animal's location (no restrictions on the values). speedX and speedY (double) - the speed in x and y directions (no restrictions on the values). o +1 One zero-arg constructor that sets energy to 100 o Several public methods: [+2] Setters and getters for all attributes except alive which should have only a getter method e * Note the following: [+2] your code must respect the restrictions on the values as indicated above +2] The energy's setter method should also display a message whenever the animal is hungry, e.g. "Cowl is hungry", or starving, e.g. "Cowl is starving", where Cow1 is the animal's name. An animal is starving when its energy s 17 and it is hungry when its energy is between 17 and 50. e [+2] toString method that returns a string representation of the animal's status similar to the following format . Alive:true Name: Cow1 Energy 100.0 Location: (0.0,0.0) [+2] void move () : if the animal is alive, increment x by speedX and y by speedY, and decrement energy by 0.1. If the animal is dead, display a message to indicate that it is dead, e.g. "Cowl can't move. It is dead!" *

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!