Question: Consider the following class representing a Pet. Write a class to represent a Dog that is a subclass of Pet. When a dog speaks, it

Consider the following class representing a Pet.

Write a class to represent a Dog that is a subclass of Pet. When a dog speaks, it will say either Woof! (70% of the time, randomly) or Bark! (30% of the time, randomly). A dog will also have a trainability factor (a whole number between 1, not trainable, to 100, easiest to train) and a list of tricks. A dog will be able to learnNewTrick, which takes an integer difficulty (also a number between 1 and 100) and the name of a new trick. If that difficulty is less than or equal to the training factor, it will successfully learn the trick (add to list of tricks) otherwise, it will not. When the dog is asked to doTrick(), it will choose one of the tricks it knows and perform it (returns name of trick).

public class Pet{ //creates a Pet with the given name & owner

public Pet(String name, String owner){

/* implementation not shown */ }

//returns the name of the current owner

public String getOwner(){

/* implementation not shown */ }

//changes the owner of this Pet

public void changeOwner(String owner){

/* implementation not shown */ } //gets the name of this pet

public String getName(){ /* implementation not shown */ }

//this pet has no sound, returns empty string

public String speak(){ /* implementation not shown */ }

//There may be other variables, constructors, and methods not shown. }

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!