Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 3 Lnai 9286

Authors: Albert Bifet ,Michael May ,Bianca Zadrozny ,Ricard Gavalda ,Dino Pedreschi ,Francesco Bonchi ,Jaime Cardoso ,Myra Spiliopoulou

1st Edition

3319234609, 978-3319234601

More Books

Students also viewed these Databases questions

Question

How does the concept of hegemony relate to culture?

Answered: 1 week ago