Question

Exercise #3: Create a class to represent a dog. Name the class “Dog”. It will contain...


Exercise #3:
Create a class to represent a dog. Name the class “Dog”. It will contain three (3) class attributes, its bark, size, and cuteness.
The bark will be the sound of the dog’s bark, as in “woof!”. Its size will be how tall the dog is from the ground, and that number should always be between 6 and 44 inches. The cuteness is a string describing how cute the dog is, based on this scale:
“ugliest dog ever!”
“pretty ugly dog.”
“ugly dog”
“average”
“cute dog.”
“pretty cute dog.”
“most adorable dog ever!”
Ensure that all of the class variables are private and that they each have an accessor (getter) and a mutator (setter).
Include a default constructor method that takes no parameters but initializes a dog object with a bark sound of “Yelp!”, a size of 20, and a cuteness of “average.”.
Provide an overloaded constructor as well, that will take in three parameters and use those parameters to set all of the class’s fields.
Next, have a method called “UpdateBark” that will change the dog’s cuteness depending on its size, since large dogs can have intimidating deep barks while smaller dogs will have higher pitched and less frightening barks.
If the dog is larger than 16 inches, its cuteness should change in a negative fashion anytime the dog barks (big dogs tend to scare people when they bark). If it is smaller than that, the dog’s cuteness should change in a positive fashion. For example, a larger dog would change from “average.” to “ugly dog.” and a smaller dog would change from “pretty cute!” to “most adorable dog ever!”. The values that you change the cuteness to should come from the list of cuteness above.
We will also have a “ToString” (C#) or “toString” (Java, C++) method, which will simply return the dog’s bark, size and cuteness.




Continued on the next page….

Exercise #4:
Create a two (2) instances of the “Dog” class in your “Main” method. One will be created using the default constructor and the other should be made using the overloaded constructor. That means that you should pass the overloaded constructor arguments that come from user input.
Print out each of the dog’s three attributes using the accessors. Then call the “UpdateBark” method for both and print out their fields again, but this time through the “ToString” method.

Example (blue is default dog’s attributes, green is the user’s dog’s):
Creating a default dog…
Finished creating a default dog!
Default dog bark sound is Yelp!
Default dog size is 20 inches.
Default dog’s cuteness is cute dog.
Continued on third page…
Please enter the sound of your dog’s bark: “MOOOOOO!”
Please enter the size of your dog: “10”
Please enter the cuteness of your dog: “ugly dog.”
Your dog bark sound is MOOOOOO!
Your dog size is 10 inches.
Your dog’s cuteness is ugly dog.
Both dogs are doing a scary bark! Their cuteness has been affected!
Default dog bark sound is Yelp!
Default dog size is 20 inches.
Default dog’s cuteness is average.
Your dog bark sound is MOOOOOO!
Your dog size is 10 inches.
Your dog’s cuteness is average.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

// Dog.java

public class Dog {
   private String bark;
   private int size;
   private String cuteness;

   /**
   * @param bark
   * @param size
   * @param cuteness
   */
   public Dog(String bark, int size, String cuteness) {
       this.bark = bark;
       this.size = size;
       this.cuteness = cuteness;
   }

   public Dog() {
       System.out.println("Creating a default dog…");
       this.bark = "Yelp";
       this.size = 20;
       this.cuteness = "average";
   }

   /**
   * @return the bark
   */
   public String getBark() {
       return bark;
   }

   /**
   * @param bark
   * the bark to set
   */
   public void setBark(String bark) {
       this.bark = bark;
   }

   /**
   * @return the size
   */
   public int getSize() {
       return size;
   }

   /**
   * @param size
   * the size to set
   */
   public void setSize(int size) {
       this.size = size;
   }

   /**
   * @return the cuteness
   */
   public String getCuteness() {
       return cuteness;
   }

   /**
   * @param cuteness
   * the cuteness to set
   */
   public void setCuteness(String cuteness) {
       this.cuteness = cuteness;
   }

   public void UpdateBark() {
       if (size > 16) {
           cuteness = "ugly dog";
       } else if (size <= 16) {
           cuteness = "most adorable dog ever!";
       }
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return "Your dog bark sound is " + bark + "\n Your dog size is " + size
               + " inches\nYour dog cuteness is " + cuteness;
   }

}
__________________________

// Test.java

import java.util.Scanner;

public class Test {

   public static void main(String[] args) {
       String bark,cuteness;
       int size;
       /*
       * Creating an Scanner class object which is used to get the inputs
       * entered by the user
       */
       Scanner sc = new Scanner(System.in);

       Dog d1=new Dog();
       System.out.println("Finished creating a default dog!");
       System.out.println("Default dog bark sound is "+d1.getBark());
               System.out.println("Default dog size is "+d1.getSize()+" inches.");
                       System.out.println("Default dog’s cuteness is "+d1.getCuteness()+".");
       System.out.println("\nDog#1:\n"+d1);
  
//Getting the input entered by the user
System.out.print("Please enter the sound of your dog's bark:");
bark=sc.nextLine();
  
System.out.print("Please enter the size of the dog:");
size=sc.nextInt();
sc.nextLine();
System.out.print("Please enter the cuteness of your dog:");
cuteness=sc.nextLine();
  
Dog d2=new Dog(bark, size, cuteness);
System.out.println("\nDog#2:\n"+d2);
  
d1.UpdateBark();
d2.UpdateBark();
System.out.println("\nDog#1:\n"+d1);
System.out.println("\nDog#2:\n"+d2);
   }

}
_____________________________

Output:

Creating a default dog…
Finished creating a default dog!
Default dog bark sound is Yelp
Default dog size is 20 inches.
Default dog’s cuteness is average.

Dog#1:
Your dog bark sound is Yelp
Your dog size is 20 inches
Your dog cuteness is average
Please enter the sound of your dog's bark:“MOOOOOO!”
Please enter the size of the dog:10
Please enter the cuteness of your dog:ugly dog

Dog#2:
Your dog bark sound is “MOOOOOO!”
Your dog size is 10 inches
Your dog cuteness is ugly dog

Dog#1:
Your dog bark sound is Yelp
Your dog size is 20 inches
Your dog cuteness is ugly dog

Dog#2:
Your dog bark sound is “MOOOOOO!”
Your dog size is 10 inches
Your dog cuteness is most adorable dog ever!

_______________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
Exercise #3: Create a class to represent a dog. Name the class “Dog”. It will contain...
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
  • 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...

  • programming in JAVA,, Declare a class Dog, objects of which have attributes age and name. The...

    programming in JAVA,, Declare a class Dog, objects of which have attributes age and name. The class has one constructor that initializes both attributes. Dog class has method bark. Objects of Dog respond to bark method by printing of "HOOF" in case when dog object's age is > 5 and "HOOF,  HOOF ,  HOOF " if the age is less than 5.

  • Write Python code to create a class called Dog which represents a dog. The Dog class...

    Write Python code to create a class called Dog which represents a dog. The Dog class should have properties of breed (i.e. what type of dog it is), name and weight. The class should also have a constructor that takes these parameters to initialise the dog object, and a method called bark that prints out the word 'Woof!' to the screen. After you have defined the Dog class, create a Dog object called goodDog with a breed of 'terrier', a...

  • 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...

  • Exercise #3: Create the “MathTest” class. It will have two class variables: 1) a question and...

    Exercise #3: Create the “MathTest” class. It will have two class variables: 1) a question and 2) the answer to that question. Exercise #4: Please create an accessor and mutator method for both of those variables, without which we would not be able to see or change the question or the answer. Exercise #5: There should be a constructor method. We will also have a “ToString” method, which will print the question followed by its answer. The constructor method has...

  • SOLVE IN PYTHON: Exercise #1: Design and implement class Circle to represent a circle object. The...

    SOLVE IN PYTHON: Exercise #1: Design and implement class Circle to represent a circle object. The class defines the following attributes (variables) and methods: A private variable of type double named radius to represent the radius. Set to 1. Constructor Methods: Python : An overloaded constructor method to create a default circle. C# & Java: Default Constructor with no arguments. C# & Java: Constructor method that creates a circle with user-specified radius. Method getRadius() that returns the radius. Method setRadius()...

  • 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...

  • Design and implement class Circle to represent a circle object. The class defines the following attributes...

    Design and implement class Circle to represent a circle object. The class defines the following attributes (variables) and methods: 1.      A private variable of type double named radius to represent the radius. Set to 1. 2.      Constructor Methods: •        Python : An overloaded constructor method to create a default circle. •        C# & Java: Default Constructor with no arguments. •        C# & Java: Constructor method that creates a circle with user-specified radius. 3.      Method getRadius() that returns the radius. 4.     ...

  • write a class encapsulating the concept of a student assuming that the student has the following...

    write a class encapsulating the concept of a student assuming that the student has the following attributes the name of student the average of the student the rite a class encapsulating the concept of a Student, assuming that the Student has the following attributes: the name of the student, the average of the student, and the student's GPA. Include a default constructor, an overloaded constructor, the accessors and mutators, and methods, toString() and equals(). Also include a method returning the...

  • Create a Mattress class should have fields for size (king, queen, twin), manufacturer, and price, and...

    Create a Mattress class should have fields for size (king, queen, twin), manufacturer, and price, and a constructor should set default values for each. Write set methods only for size and manufacturer. The set method for size adds $200 for king or $100 for queen. Add a toString() method that returns the data from all of the fields. A child class named AdjustableMattress extends Mattress and adds a field for adjustment type (air or mechanical), with air being the default....

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