Last active
September 15, 2024 10:12
-
-
Save iamtakagi/78d58aea0858cd5f2bd2fba0ff540ca1 to your computer and use it in GitHub Desktop.
親から"犬"という種族名を受け継ぐはずが「敷かれたレールは嫌だから」という理由で継がなかったため、世間から"動物"と呼ばれるようになった動物
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package social; | |
import java.util.Random; | |
enum Sex { | |
MALE, FEMALE | |
} | |
class God { | |
private final static Random random = new Random(); | |
private static Sex decideSex() { | |
Sex[] sexes = Sex.values(); | |
return sexes[random.nextInt(sexes.length)]; | |
} | |
} | |
abstract class Animal { | |
abstract Sex getSex(); | |
abstract Animal makeChildren(Animal partner); | |
abstract String getCallName(); | |
} | |
class Dog extends Animal { | |
private Sex sex; | |
private boolean hateSocialRails = false; | |
protected Dog(Sex sex) { | |
this.sex = sex; | |
} | |
protected Sex getSex(){ | |
return this.sex; | |
} | |
protected Animal makeChidren(Animal partner) { | |
if(partner == null) return null; | |
return new Dog(God.decideSex()); | |
} | |
protected String getCallName() { | |
return isHateSocialRails() ? "動物" : "犬"; | |
} | |
protected void setHateSocialRails(boolean hateSocialRails) { | |
this.hateSocialRails = hateSocialRails; | |
} | |
private boolean isHateSocialRails(){ | |
return isHateSocialRails; | |
} | |
} | |
public class Main { | |
public static void main(String[] args){ | |
final Dog fatherDog = new Dog(Sex.MALE); | |
final Dog motherDog = new Dog(Sex.FAMLE); | |
final Dog chidrenDog = motherDog.makeChidren(fatherDog); | |
chidrenDog.setHateRails(true); | |
System.out.print(chidrenDog.getCallName()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment