泡妞计划-java

来源:互联网 发布:python黑客编程 编辑:程序博客网 时间:2024/06/09 20:16


package com.qianfeng.day10.demo4;


 


public abstract class Plan {


      privateGirl girl;//使用聚合(组合),本类中,声明了引用变量都算是聚合


      privateBoy boy;//有引用属性时就用聚合,比如girlboy


      


      publicPlan(Girl girl, Boy boy){


             this.girl = girl;


             this.boy = boy;


      }


      


      public  void chat(){


 


      };


      public  void dinner(){


 


      };


      public  void movie(){


 


      };


      public  void shopping(){


 


      };


      public  void forLove(){


 


      };


      publicGirl getGirl() {//属性私有化了,只能用setget方法访问


             return girl;


      }


      publicvoid setGirl(Girl girl) {


             this.girl = girl;


      }


      publicBoy getBoy() {


             return boy;


      }


      publicvoid setBoy(Boy boy) {


             this.boy = boy;


      }


      


      publicabstract void doPlan();


}


 


 


 


package com.qianfeng.day10.demo4;


 


public class Boy {


      privateString name;


 


      publicString getName() {


             return name;


      }


 


      publicvoid setName(String name) {


             this.name = name;


      }


 


      publicBoy(String name) {


             this.name = name;


      }


      /*publicvoid chat() {


             System.out.println("" + this.getGirl().getName() +"一起聊天");


      }


 


      publicvoid movie() {


             System.out.println("" + this.getGirl().getName() +"看电影");


      }


 


      publicvoid shopping() {


             System.out.println("" + this.getGirl().getName() +"shopping");


      }


 


      publicvoid forLove() {


             System.out.println("" + this.getGirl().getName() +"表白");


      }


      


      publicvoid dinner() {


             System.out.println("" + this.getGirl().getName() +"烛光晚餐");


      }*/


      


      


      publicvoid paoNiu(Plan plan){


             plan.doPlan();


      }


      


      


      


      


}


 


 


package com.qianfeng.day10.demo4;


 


public class Girl {


      privateString name;


 


      publicString getName() {


             return name;


      }


      publicvoid setName(String name) {


             this.name = name;


      }


      publicGirl(String name){


             this.name = name;


      }


}


 


 


package com.qianfeng.day10.demo4;


 


public class PlanA extends Plan {


      


      publicPlanA(Girl girl , Boy boy){


             super(girl, boy);


      }


      


      public  void chat(){


             System.out.println(super.getBoy().getName()+ "" +


                                 super.getGirl().getName()+ "暗送求波....");


      };


      


      public  void forLove(){


             /*System.out.println("可惜了," +super.getGirl().getName()


                          + "要求,没有1000w身价,免谈~");*/


            


             System.out.println("欧巴,我愿意~~");


            


      };


      


      @Override


      publicvoid doPlan() {


             chat();


             forLove();


      }


}


 


 


package com.qianfeng.day10.demo4;


 


public class PlanB extends Plan{


 


      publicPlanB(Girl girl, Boy boy) {


             super(girl, boy);


      }


      


 


      public  void chat(){


             System.out.println(super.getBoy().getName()+ "" +


                                 super.getGirl().getName()+ "暗送求波....");


      };


      


      public  void dinner(){


             System.out.println(super.getBoy().getName()+"@"


                          + super.getGirl().getName() + "走,去吃猪脚饭...");


      };


      


      public  void movie(){


             System.out.println(super.getBoy().getName()+"@"


                          + super.getGirl().getName() + ":看午夜凶铃去,别想歪了,我就想看恐怖片...");


      };


 


      public  void forLove(){


             System.out.println("不好意思,你是个好人~");


      };


 


      @Override


      publicvoid doPlan() {


             for(int i = 0; i < 4; i++){


                    chat();


                    dinner();


                    movie();


                    forLove();


             }


      }


}


 


 


package com.qianfeng.day10.demo4;


 


public class Test {


      publicstatic void main(String[] args) {


             /*Girl girl = new Girl("刘亦菲");


             Boy boy = new  Boy("隔壁老王");


            


             boy.setGirl(girl); //泡妞对象


             boy.chat();


             boy.dinner();


            


             Girl girl2 = new Girl("范冰冰");


             boy.setGirl(girl2); //泡妞对象


            


             boy.chat();


             boy.dinner();*/


            


             Girl girl = new Girl("罗玉凤");


             Boy boy = new  Boy("隔壁老王");


             PlanA planA = new PlanA(girl, boy);


             PlanB planB = new PlanB(girl, boy);


            


             //boy.paoNiu(planA);


             boy.paoNiu(planB);


      }


}



0 0
原创粉丝点击