Created
September 28, 2023 09:23
-
-
Save kishida/fbcb63f3b26552ed7f3daec84ba744bc to your computer and use it in GitHub Desktop.
classes that ChatGPT generated from class diagram image
This file contains hidden or 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
// 基本的なMammalクラス | |
public abstract class Mammal { | |
private int height; | |
private int weight; | |
public Mammal(int height, int weight) { | |
this.height = height; | |
this.weight = weight; | |
} | |
public int getHeight() { | |
return height; | |
} | |
public void setHeight(int height) { | |
this.height = height; | |
} | |
public int getWeight() { | |
return weight; | |
} | |
public void setWeight(int weight) { | |
this.weight = weight; | |
} | |
public abstract String cry(); | |
} | |
// ColorPatternを表す簡単な列挙型 | |
enum ColorPattern { | |
STRIPED, SPOTTED, SOLID | |
} | |
// Mammalを継承したCatクラス | |
public class Cat extends Mammal { | |
private ColorPattern colorPattern; | |
public Cat(int height, int weight, ColorPattern colorPattern) { | |
super(height, weight); | |
this.colorPattern = colorPattern; | |
} | |
public ColorPattern getColorPattern() { | |
return colorPattern; | |
} | |
public void setColorPattern(ColorPattern colorPattern) { | |
this.colorPattern = colorPattern; | |
} | |
@Override | |
public String cry() { | |
return "ニャー"; | |
} | |
} | |
// Breedを表す簡単な列挙型 | |
enum Breed { | |
LABRADOR, BULLDOG, SHEPHERD | |
} | |
// Mammalを継承したDogクラス | |
public class Dog extends Mammal { | |
private Breed breed; | |
public Dog(int height, int weight, Breed breed) { | |
super(height, weight); | |
this.breed = breed; | |
} | |
public Breed getBreed() { | |
return breed; | |
} | |
public void setBreed(Breed breed) { | |
this.breed = breed; | |
} | |
@Override | |
public String cry() { | |
return "ワンワン"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment