In: Computer Science
Here is class Dog
-String name; -int age
-String breed;
-boolean adopted; //false if available ………………… +constructor, getters, setters, toString() Write a lambda expression showAdoptable using a standard functional interface that will display the dog’s name age and breed if adopted is false.
Help please!!
Here is the code for the above requirements in JAVA:
@FunctionalInterface
interface PrintIfNotAdopted{
        String showAdoptable();
}
class Dog implements PrintIfNotAdopted{
    String name;
    int age;
    String breed;
    boolean adopted;
    public Dog(String name, int age, String breed, boolean adopted){
        this.name = name;
        this.age = age;
        this.breed = breed;
        this.adopted = adopted;    
    }
    
    public String getName(){
         return name;
    } 
    public void setName(String name){
         this.name = name;
    } 
    public int getAge(){
         return age;
    } 
    public void setAge(int age){
         this.age = age;
    } 
    public String getBreed(){
         return breed;
    } 
    public void setBreed(String breed){
         this.breed = breed;
    } 
    public boolean getAdopted(){
         return adopted;
    } 
    public void setAdopted(boolean adopted){
         this.adopted = adopted;
    } 
     
    public String toString(){
        return "DOG NAME: "+name+", DOG AGE: "+age+", DOG BREED: "+breed+", IS ADOPTED: "+adopted;    
    }
    
        @Override
        public String showAdoptable() {
         if(!adopted){
            return "DOG IS NOT ADOPTED: NAME: "+name+", AGE: "+age+", BREED: "+breed;    
          }       
          else{return "";} 
        }
    public static void main(String[] args){
        Dog d1 = new Dog("Bruno",12,"Wild",false);
        System.out.println(d1.toString());               
        System.out.println(d1.showAdoptable());    
    }
}
Output when Dog is adopted:

Output when Dog is not adopted:

I hope this will help you. Thanks.