(a) Add the class Parrot in the answer box below, making it a subclass of Bird. (b) Add a private instance variable to t

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
correctanswer
Posts: 43759
Joined: Sat Aug 07, 2021 7:38 am

(a) Add the class Parrot in the answer box below, making it a subclass of Bird. (b) Add a private instance variable to t

Post by correctanswer »

(a) Add the class Parrot in the answer box below, making it a
subclass of Bird.
(b) Add a private instance variable to the class called talking
of type boolean.
(c) Add a public constructor for Parrot whose first parameter is
used to set the parrot's name and whose second parameter is the
parrot's description.
The instance variable talking should be set to false
(d) Add standard getter and setter methods for talking called
isTalking and setTalking.
(e) Add a public method addPhrase that adds the string phrase
passed as argument to vocabulary. The method does not
return a value.
(f) Add a public method sayPhrase that does not return a value
and takes a string argument representing a phrase the parrot might
say. It should have the following effects depending on the value of
talking and whether the phrase is in vocabulary or not:
(g) Add a public method updateFavouriteFood which takes a String
argument and does not return a value. The method should prefix the
parrot's favourite food with the String passed as argument and a
space.
E.g. If favouriteFood is currently set to "seeds" and the
argument passed is "thistle" then the method should set
favouriteFood to "thistle seeds".
(h) Override the toString method inherited from Bird to add the
text:
" and is talking" or " and is not talking" depending on the
value of talking.
(i) Add a public method resetFavouriteFood that takes no
argument and does not return a value. It should reset the parrot's
favourite food to the characters after the first space if any in
favouriteFood. If there is no space the favourite food should be
unchanged
Register for solutions, replies, and use board search function. Answer Happy Forum is an archive of questions covering all technical subjects across the Internet.
Post Reply