Adds v2 for bird.

This commit is contained in:
Tanmay 2022-09-07 16:10:47 +01:00
parent c90260eac1
commit 95fb52ddb5
4 changed files with 41 additions and 10 deletions

View File

@ -5,20 +5,12 @@ import lombok.Getter;
@AllArgsConstructor
@Getter
public class Bird {
public abstract class Bird {
private Integer weight;
private String colour;
private String size;
private String beakType;
private BirdType type;
public void fly() {
if (type == BirdType.Eagle) {
System.out.println("Eagle is flying");
} else if (type == BirdType.Penguin) {
System.out.println("Penguin is swimming");
} else if (type == BirdType.Parrot) {
System.out.println("Parrot is flying");
}
}
public abstract void fly();
}

View File

@ -0,0 +1,14 @@
package com.scaler.lld.bird;
public class Eagle extends Bird {
public Eagle(Integer weight, String colour, String size, String beakType, BirdType type) {
super(weight, colour, size, beakType, type);
}
@Override
public void fly() {
System.out.println("\nEagle is flying");
}
}

View File

@ -0,0 +1,14 @@
package com.scaler.lld.bird;
public class Parrot extends Bird {
public Parrot(Integer weight, String colour, String size, String beakType, BirdType type) {
super(weight, colour, size, beakType, type);
}
@Override
public void fly() {
System.out.println("\nParrot is flying");
}
}

View File

@ -0,0 +1,11 @@
package com.scaler.lld.bird;
public class Runner {
public static void main(String[] args) {
Bird parrot = new Parrot(10, "Green", "Small", "Sharp", BirdType.Parrot);
parrot.fly();
Bird eagle = new Eagle(20, "Brown", "Medium", "Sharp", BirdType.Eagle);
eagle.fly();
}
}