Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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?).image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Database Programming With Visual Basic.NET

Authors: Ying Bai

1st Edition

0521712351, 978-0521712354

More Books

Students also viewed these Databases questions

Question

How many bistables would you expect to find in the mbeds SRAM?

Answered: 1 week ago

Question

Information architecture is a term primarily used by:

Answered: 1 week ago