泡妞计划-java
2016-01-14 00:18
417 查看
package com.qianfeng.day10.demo4;
public abstract
class Plan {
privateGirl girl;//使用聚合(组合),本类中,声明了引用变量都算是聚合
privateBoy boy;//有引用属性时就用聚合,比如girl和boy
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);
}
}
public abstract
class Plan {
privateGirl girl;//使用聚合(组合),本类中,声明了引用变量都算是聚合
privateBoy boy;//有引用属性时就用聚合,比如girl和boy
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);
}
}
相关文章推荐
- Eclipse+Pydev环境下使用utf-8编码
- 女孩 鸟交互--java
- java--属性的继承
- java--重写 final (课堂笔记)
- java--匿名内部类
- java--静态属性和非静态属性的赋值与取值
- java--内部类(局部)
- java-- 静态内部
- java接口,private,final,static组合(课堂)
- java--继承和构造方法重载(课堂)
- spring boot 1.5.4 集成shiro+cas,实现单点登录和权限控制
- Eclipse SSM Maven Web项目(一)
- Eclipse SSM Maven Web项目(二)
- java--继承,访问权限,方法(课堂)
- Java泛型--<? extends>和<? super>
- Java enum的用法详解
- mac osx 10.10以上系统无法安装jdk问题
- java抽象类(课堂)
- java类加载机制与反射
- java内部类(成员)(课堂)