Question

Could someone help me out. I am not sure what I should be doing. Seeing it worked out will allow me to understand what I should be doing and then I can complete it on my own.

Usando 2. Complete the Dog Class: a. Using the UML Class diagram to the right declare the instance variables. A text version

DogApp/DogApp: O Dog.java X Corgijava 1 public class Dog { // instance variables // constructor // methods NN HAPP OD 00 onih

DogApp/DogApp/Corgijava - Eclipse Dog.java Corgi java X 1 public class Corgi extends Dog { 77 additional instance variables 7

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Initially we have to complete the Dog class,below is code along with snapshot:

public class Dog {// class dog.
   String type,breed,name,topTrick; // Instance Variable Declared.
  
   Dog(String type,String breed,String name){ // Constructor of class Dog.
       this.type = type;
       this.breed = breed;
       this.name = name;
       //Initializing the instance variables.
   }
  
   public void setTopTrick(String topTrick) { // Defined Mutator Method.
       this.topTrick = topTrick; // setting instance variable topTrick.
   }
  
   @Override
   public String toString() {
       String temp = "DOG DATA\n" + name + " is a " + breed + " Corgi" + ", a " + type + " dog.\n"
                       +"The top trick is: "+ topTrick+".";
       return temp;
       // Overriding toString method.
}
}

public class Dog {// class dog. String type, breed, name, topTrick; // Instance Variable Declared. Dog (String type, String b

after completing Dog class,we have to complete Corgi Class which is inherited from Dog Class.

Following is the code for Corgi class below with snapshot:

public class Corgi extends Dog{// Corgi class inherited from Dog class.
   int weight,age; // Declared Instance Variable of class Corgi.
  
   public Corgi(String type,String breed,String name,int weight,int age)
   {// Parameterized Constructor of class Corgi.
       super(type,breed,name); //calling super class.
       this.weight = weight;
       this.age = age;
       // Initializing Instance Variable.
   }
  
   public void setWeight(int weight) { //mutator method for Weight
       this.weight = weight;// setting instance variable weight.
   }
  
   public void setAge(int age) { //mutator method for Age
       this.age = age;// setting instance variable age.
   }
  
   @Override
   public String toString() {
       String temp = "\nThe Corgi is " + age + " years old and weighs " + weight + " pounds.";
       return super.toString()+temp;
       // Overriding toString method.
   }
}

public class Corgi extends Dog{// Corgi class inherited from Dog class. int weight, age; // Declared Instance Variable of cla

Now as per the question below is the code for driver class with snapshot:

public class driver {
   public static void main(String args[]) {
       Corgi obj = new Corgi("cattle herding","Pembroke Welsh","Java",38,5);
       obj.setTopTrick("ringing the bell to go outside");
       System.out.println(obj.toString());
   }
}
public class driver { public static void main(String args[]) { // object of class Corgi. Corgi obj = new Corgi(cattle herdin

Below is the output based on the given inputs in the driver class:

Problems @ Javadoc a Declaration Console X <terminated> driver [Java Application] C:\Program Files\Java\jre1.8.0_241\bin\java

for defining mutator method press Alt + Shift + S and select Generate getters and setters.

and select variables from the window and click on generate.

Setters is also known as Mutator and Getters is also known as Accessors.

(If You like my Answer then please Upvote).

Thank you.

Add a comment
Know the answer?
Add Answer to:
Could someone help me out. I am not sure what I should be doing. Seeing it...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java file Name Dog Classes and Methods Create a constructor that incorporates the type, breed, and...

    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: Using the UML Class diagram, declare the instance variables. Create the two...

  • In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in...

    In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in 'Dog' : name (String type) age (int type) 2. declare the constructor for the 'Dog' class that takes two input parameters and uses these input parameters to initialize the instance variables 3. create another class called 'Driver' and inside the main method, declare two variables of type 'Dog' and call them 'myDog' and 'yourDog', then assign two variables to two instance of 'Dog' with...

  • Using your Dog class from earlier this week, complete the following: Create a new class called...

    Using your Dog class from earlier this week, complete the following: Create a new class called DogKennel with the following: Instance field(s) - array of Dogs + any others you may want Contructor - default (no parameters) - will make a DogKennel with no dogs in it Methods: public void addDog(Dog d) - which adds a dog to the array public int currentNumDogs() - returns number of dogs currently in kennel public double averageAge() - which returns the average age...

  • In Java Code Needed is Below the Question Using Program 3: Encapsulating Dogs, modify this program...

    In Java Code Needed is Below the Question Using Program 3: Encapsulating Dogs, modify this program to create a database of dogs of your own. You will also include File I/O with this program. You will create 3 classes for this assignment. The first class: Create a Class representing the information that is associated with one item (one dog) of your database. Name this class Dog. Using Lab 3, this will include the information in regard to one dog. The...

  • Java Create four classes: 1.      An Animal class that acts as a superclass for Dog and...

    Java Create four classes: 1.      An Animal class that acts as a superclass for Dog and Bird 2.      A Bird class that is a descendant of Animal 3.      A Dog class that is a descendant of Animal 4.      A “driver” class named driver that instantiates an Animal, a Dog, and a Bird object. The Animal class has: ·        one instance variable, a private String variable named   name ·        a single constructor that takes one argument, a String, used to set...

  • Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the...

    Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the concept of a college course, assuming that a course has following attributers: code (for instance COSC1337), a description, and a number of credits (for instance 3). Include a constructor, the accessors, mutators and methods ‘toString’, ‘equals’, and ‘finalize’. Write a client class to test the behavior of the class and its methods. The outline of the class is given as follows: public class Course...

  • Java Program Please help me with this. It should be pretty basic and easy but I...

    Java Program Please help me with this. It should be pretty basic and easy but I am struggling with it. Thank you Create a superclass called VacationInstance Variables destination - String budget - double Constructors - default and parameterized to set all instance variables Access and mutator methods budgetBalance method - returns the amount the vacation is under or over budget. Under budget is a positive number and over budget is a negative number. This method will be overwritten in...

  • Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram)

    Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram) Author -name:String -email:String -gender:char +Author(name:String, email:String, gender:char) +getName():String +getEmail):String +setEmail (email:String):void +getGender():char +tostring ):String . Three private instance variables: name (String), email (String), and gender (char of either 'm' or 'f'): One constructor to initialize the name, email and gender with the given values . Getters and setters: get Name (), getEmail() and getGender (). There are no setters for name and...

  • Define a class named Payment that contains an instance variable "paymentAmount" (non-static member variable) of type...

    Define a class named Payment that contains an instance variable "paymentAmount" (non-static member variable) of type double that stores the amount of the payment and appropriate accessor (getPaymentAmount() ) and mutator methods. Also create a method named paymentDetails that outputs an English sentence to describe the amount of the payment. Override toString() method to call the paymentDetails() method to print the contents of payment amount and any other details not included in paymentDetails(). Define a class named CashPayment that is...

  • Code in JAVA UML //TEST HARNESS //DO NOT CHANGE CODE FOR TEST HARNESS import java.util.Scanner; //...

    Code in JAVA UML //TEST HARNESS //DO NOT CHANGE CODE FOR TEST HARNESS import java.util.Scanner; // Scanner class to support user input public class TestPetHierarchy { /* * All the 'work' of the process takes place in the main method. This is actually poor design/structure, * but we will use this (very simple) form to begin the semester... */ public static void main( String[] args ) { /* * Variables required for processing */ Scanner input = new Scanner( System.in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT