Ask Question
24 June, 00:50

For this assignment you will write a class called Dog that has the following member variables:

birthyear. An int that holds the dog's birth year.

breed. A string that holds the breed of dog.

vaccines. A Boolean holding a yes/no value indicating whether the dog is currently on vaccinations. In addition, the class should have the following member functions:

Constructor. The constructor should accept the dog's birthyear, breed and vaccines as arguments and assign these values to the object's birthyear, breed and vaccines member variables.

Accessors. Appropriate accessor functions should be created to allow values to be retrieved from an object's birthyear, breed and vaccines member variables.

Demonstrate the class in a program that creates a Dog object. The user should enter all input. Be sure to include comments throughout your code where appropriate.

+5
Answers (1)
  1. 24 June, 03:44
    0
    import java. util. Scanner;

    public class Dog {

    private int birthYear;

    private String breed;

    private boolean isVaccinated;

    / / The constructor

    public Dog (int birthYear, String breed, boolean isVaccinated) {

    this. birthYear = birthYear;

    this. breed = breed;

    this. isVaccinated = isVaccinated;

    }

    / / The Accesor Methods

    public int getBirthYear () {

    return birthYear;

    }

    public void setBirthYear (int birthYear) {

    this. birthYear = birthYear;

    }

    public String getBreed () {

    return breed;

    }

    public void setBreed (String breed) {

    this. breed = breed;

    }

    public boolean isVaccinated () {

    return isVaccinated;

    }

    public void setVaccinated (boolean vaccinated) {

    isVaccinated = vaccinated;

    }

    }

    //A program that creates the Dog Object

    class DogTest{

    public static void main (String[] args) {

    //Requesting details of the Dog from User

    System. out. println ("Enter Dog year of birth");

    Scanner in = new Scanner (System. in);

    int year = in. nextInt ();

    System. out. println ("Enter Dog breed");

    String breed = in. next ();

    System. out. println ("Is Dog vaccinated");

    boolean isVaccinated = in. nextBoolean ();

    //Creating an Object of the Dog class

    Dog DogOne = new Dog (year, breed, isVaccinated);

    System. out. println ("The Dog's Breed is is "+DogOne. getBreed ());

    }

    }

    Explanation:

    Create two class Dog and DogTest

    Define all the class members in the Dog class (The three variables, constructor and accessor methods)

    Create the main method in the DogTest class, create an instance of the Dog class.

    Use scanner class to request the attributes of a new Dog
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “For this assignment you will write a class called Dog that has the following member variables: birthyear. An int that holds the dog's birth ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers