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