しろたん.java Java X Facebook はてブ Pocket LINE コピー 2003.06.232020.02.12 Sirotan.java public class Sirotan{ public static void main(String argv[]){ System.out.println("きゅー"); } }
コメント
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();
}
}
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()+”しろたんだよ!”);
}
}
}
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();
}
}
public class Clothes {
private String type=””;
public Clothes(String _type){
this.type=_type;
}
public String getType(){
return this.type;
}
}
さぁレッツ、コンパイル・実行してみよう!
#抽象化が微妙だが・・
実行しないでもわかるよ!!