Answer:
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());
}
}
Step-by-step 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