Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Database Internals A Deep Dive Into How Distributed Data Systems Work

Authors: Alex Petrov

1st Edition

1492040347, 978-1492040347

More Books

Students also viewed these Databases questions

Question

Did you offer hard data that is verifiable? [D]

Answered: 1 week ago