Skip to content

Instantly share code, notes, and snippets.

@kishida
Created September 28, 2023 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kishida/fbcb63f3b26552ed7f3daec84ba744bc to your computer and use it in GitHub Desktop.
Save kishida/fbcb63f3b26552ed7f3daec84ba744bc to your computer and use it in GitHub Desktop.
classes that ChatGPT generated from class diagram image
// 基本的な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