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
Exercise #3: Create a class to represent a dog. Name the class “Dog”. It will contain...
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 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 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 '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 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 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 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 (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 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 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....