1 answer

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

Question:

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.

Answers

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

.

Similar Solved Questions

1 answer
12A. On December 31, 2018, when the market interest rate is 10%, Derrick Corporation issues $240,000...
12A. On December 31, 2018, when the market interest rate is 10%, Derrick Corporation issues $240,000 of 7%, 12-year bonds payable. The bonds pay interest semiannually. Determine the present value of the bonds at issuance. (Click the icon to view Present Value of $1 table.) 6 (Click the icon to view ...
1 answer
1. Calculate the CS, PS, the externality cost, and overall surplus in the absence of the...
1. Calculate the CS, PS, the externality cost, and overall surplus in the absence of the tax. Then calculate these again under the tax, taking into account the tax revenue raised. Calculating the various triangles, we get the results as outlines in the table below. When calculating the external cost...
1 answer
Alternate Homework 13 14 ANOVA Problems 2 A nuclear reactor experiences a radiation leak. The following...
Alternate Homework 13 14 ANOVA Problems 2 A nuclear reactor experiences a radiation leak. The following data is measurements of radiation at three locations near the reactor. Perform a hypothesis test at 95% confidence to determine if the population mean radiation levels (for the three locations) co...
1 answer
Discuss the differnet types of unemployment (structural, natural rate, cyclical and frictional) that are likely to...
discuss the differnet types of unemployment (structural, natural rate, cyclical and frictional) that are likely to be affected by this pandemic in kuwait....
1 answer
Quest. 2 (15 pts A 6.50 g sample of a nonelectrolyte is dissolved in 97.8 mL...
Quest. 2 (15 pts A 6.50 g sample of a nonelectrolyte is dissolved in 97.8 mL of hydrogen acetate (density of hydrogen acetate is 1.24 g/mL) is found to freeze at 11.3 C. a) What is the molar mass of this compound? b) What would be the predicted molar mass of the compound if it was?? an electrolyte c...
1 answer
Answer with steps please 4. Figure below shows a rotating shaft simply supported in ball bearings...
answer with steps please 4. Figure below shows a rotating shaft simply supported in ball bearings at A and D and loaded by a nonrotating force F of 6.8 kN. The shaft is made AISI/SAE cold drawn 1050 steel, estimate the life of the part. 550 C 400 B - 6.8 EN 75 -100 - 250 --- -125 Stress amplitude...
1 answer
Download the attached file of data, and recover the equation of the regression line through the...
Download the attached file of data, and recover the equation of the regression line through the data. Assignment 26 Q1 Data What is the value of bo? Round to four decimals and use leading zeros if necessary. 75294 11212 21880 122...
1 answer
Choose ONE of the costing systems studied in this unit from the list below, and answer...
Choose ONE of the costing systems studied in this unit from the list below, and answer the questions that follow: • Job Costing • Process Costing • Operation Costing (Hybrid Costing) • Activity-based Costing (ABC) Questions: 1. Briefly discuss the features of your chosen costing ...
1 answer
If a projectile is fired with an initial velocity of vo meters per second at an...
If a projectile is fired with an initial velocity of vo meters per second at an angle a above the horizontal and air resistance is assumed to be negligible, then its position after t seconds is given by the parametric equations x = (vo cos(a)t y = (vo sin(a)t - +- 1012 where g is the acceleration du...
1 answer
A person jumps from a window 29 meters high and is caught in a firefighter's net...
A person jumps from a window 29 meters high and is caught in a firefighter's net which stretches 0.6 meter. To the nearest m/s^2, what is the magnitude of the person's acceleration in the net?...
1 answer
Obj. 2, 3 Darby Company, operating at full capacity, sold 500,000 units at a price of...
Obj. 2, 3 Darby Company, operating at full capacity, sold 500,000 units at a price of $94 per unit during the current year. Its income statement is as follows: Show $ 47,000,000 25,000,000 $ 22,000,000 Sales ... Cost of goods sold...... Gross profit........ Expenses: Selling expenses............. Ad...
1 answer
Consider the spectrum of [V(H2O).]3+ in aqueous solution below and answer the questions that follow 17,000...
Consider the spectrum of [V(H2O).]3+ in aqueous solution below and answer the questions that follow 17,000 cm 24,500 cm Absorbance Warenumber cm (a) What is the free-ion term for the electronic arrangement of the metal-ion? Use the appropriate Tanabe-Sugano diagram to assign the absorbance bands in ...
1 answer
We were unable to transcribe this imageJournal entry worksheet < 1 3 4 5 6 7...
We were unable to transcribe this imageJournal entry worksheet < 1 3 4 5 6 7 8 Record the interest accrued on the note as of June 30, 2018. Note: Enter debits before credits. Date General Journal Debit Credit Jun 30, 2018 We were unable to transcribe this imageJournal entry worksheet < 1 2 3 4...
1 answer
A solution contains 1.48x102 M zinc nitrate and 9.13*10' M lead acetate. Solid potassium sulfide is...
A solution contains 1.48x102 M zinc nitrate and 9.13*10' M lead acetate. Solid potassium sulfide is added slowly to this mixture. What is the concentration of lead ion when zinc ion begins to precipitate? [Pb2') = M...
1 answer
Hi, it is one question with parts (a,b,c,d) also complete the table
Hi, it is one question with parts (a,b,c,d) also complete the table 2. A flask is charged with 1.000 mol of A and allowed to react to form B according to the reaction A (g) 2B (g). The following data is obtained for [A] as the reaction proceeds. (10) Complete the table. 0,0 100 200 300 400 Tim...
1 answer
The small cylinder of a hydraulic press has an area of 2"(squared)
the small cylinder of a hydraulic press has an area of 2"(squared). If a force of 10# is applied to the small piston, how much is the pressure within the larger cylinder increased, according to pascal's principle....
1 answer
Q4. (25 marks) Yamaha Company reported operating income for Year 2 of $1,600,000 under variable costing...
Q4. (25 marks) Yamaha Company reported operating income for Year 2 of $1,600,000 under variable costing and $1,200,000 under absorption costing. The total variable manufacturing cost of the company's beginning finished goods inventory was $120,000. The cost of the company's end-of-year finis...