コメント

  1. mya より:

    public class Main {
    public static void main(String[] args){
    Owner matsubokkuri = new Owner(“まつぼっくり”);
    Owner mya = new Owner (“みゃ”);

    Sirotan dolphin = new Sirotan(“まつちろ”, “いるか”);
    Sirotan penguin = new Sirotan(“みゃちろ”, “ぺんぎん”);

    matsubokkuri.getSirotan(dolphin);
    mya.getSirotan(penguin);

    matsubokkuri.speakWMySirotan();
    mya.speakWMySirotan();
    }
    }

  2. mya より:

    public class Owner {
    private Sirotan my_sirotan;
    private String my_name;

    public Owner(String _my_name){
    this.my_name = _my_name;
    }

    public void getSirotan(Sirotan siro){
    this.my_sirotan = siro;
    }

    public void speakWMySirotan(){
    if((this.my_name).equals(“まつぼっくり”)){
    System.out.println(“ぼく”+this.my_sirotan.getName()+”!”+this.my_name+”の”+this.my_sirotan.getType()+”しろたんだよ! みゃ大好きぃ。”);
    }else if(this.my_name.equals(“みゃ”)){
    System.out.println(“ぼく”+this.my_sirotan.getName()+”!”+this.my_name+”の”+this.my_sirotan.getType()+”しろたんだよ! まつぼっくりのばーか!”);
    }else if(this.my_sirotan.equals(null)){
    System.out.println(“しろたんをもってないよ。”);
    }else{
    System.out.println(“ぼく”+this.my_sirotan.getName()+”!”+this.my_name+”の”+this.my_sirotan.getType()+”しろたんだよ!”);
    }
    }
    }

  3. mya より:

    public class Sirotan {
    private String my_name;
    private Clothes my_clothes;

    public Sirotan(String name, String type){
    this.my_name= name;
    this.my_clothes = new Clothes(type);
    }

    public String getName(){
    return this.my_name;
    }

    public String getType(){
    return this.my_clothes.getType();
    }
    }

  4. mya より:

    public class Clothes {
    private String type=””;

    public Clothes(String _type){
    this.type=_type;
    }

    public String getType(){
    return this.type;
    }
    }

  5. mya より:

    さぁレッツ、コンパイル・実行してみよう!

  6. matsu より:

    #抽象化が微妙だが・・
    実行しないでもわかるよ!!

タイトルとURLをコピーしました