泡妞计划-java


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
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小猿成长

你的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值