Question: Java file Name Dog Classes and Methods Create a constructor that incorporates the type, breed, and name variables (do not include topTrick). Note: The type

Java file

Name Dog Classes and Methods

Create a constructor that incorporates the type, breed, and name variables (do not include topTrick). Note: The type refers to what the breed typically does; for example, a corgi would be a cattle herding dog. A Shiba Inu would be a hunting dog.

Create the setTopTrick() mutator method

Dog is parent class

Corgi and Driver are subclasses

Complete the Corgi class:

  1. Using the UML Class diagram, declare the instance variables.
  2. Create the two mutator methods for the instance variables.

Driver is subclass

then create the code:

  1. There should be no instance variables.
  2. The main() method will be the only method in the class.
  3. Write three lines of code in the main() method:
    1. Instantiate a corgi object using the below syntax:

className objectName = new className(input parameters)

  1. TIP: Refer to the constructors in the Dog and Corgi classes to ensure the input parameters are correct.
  2. Use the objectName.setTopTrick() method to set a top trick for the dog you created.
  3. Embed the objectName.toString() method in a statement that outputs to the console window.

Sample output:

DOG DATA

Java is a Pembroke Welsh Corgi, a cattle herding dog.

The top trick is: ringing the bell to go outside.

The Corgi is 5 years old and weighs 38 pounds.

Dog

type: string breed: string name: string

topTrick: string

setTopTrick(trick:string) toString()

Corgi

weight:int age:int

setWeight(pounds:int) setAge(years:int) toString()

Arrow pointing from table labeled Corgi to table labeled Dog

1st program : Parent Dog

public class Dog {

// instance variables

// constructor

// methods

// method used to print Dog information

public String toString() {

String temp = " DOG DATA " + name + " is a " + breed +

", a " + type + " dog. The top trick is : " +

topTrick + ".";

return temp;

}

}

2nd program Corgi

public class Corgi extends Dog {

// additional instance variables

// constructor

public Corgi(String type, String breed, String name, int pounds, int years) {

// invoke Dog class (super class) constructor

super(type, breed, name);

weight = pounds;

age = years;

}

// mutator methods

// override toString() method to include additional dog information

@Override

public String toString() {

return (super.toString() + " The Corgi is " + age +

" years old and weighs " + weight + " pounds.");

}

}

3rd program Driver (CockerSpaniel)

public class Driver extends Dog {

// additional instance variables

// constructor

public Driver(String type, String breed, String name, int pounds, int years) {

// invoke Dog class (super class) constructor

super(type, breed, name);

weight = pounds;

age = years;

}

// mutator methods

// override toString() method to include additional dog information

@Override

public String toString() {

return (super.toString() + " The Cocker Spaniel is " + age +

" years old and weighs " + weight + " pounds.");

}

}

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!