Skip to content

Instantly share code, notes, and snippets.

@iamtakagi
Last active April 8, 2023 10:24
Show Gist options
  • Save iamtakagi/78d58aea0858cd5f2bd2fba0ff540ca1 to your computer and use it in GitHub Desktop.
Save iamtakagi/78d58aea0858cd5f2bd2fba0ff540ca1 to your computer and use it in GitHub Desktop.
親から"犬"という種族名を受け継ぐはずが「敷かれたレールは嫌だから」という理由で継がなかったため、世間から"動物"と呼ばれるようになった動物
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