/** * 爱情程序,一段程序描写了一段心情 * 一个程序员的另类述说 * @author yongtree * */ public class Love {
// 我们之间的结局 public boolean loveResult(Me me, You you) { me.Miss(you.getName(), me.getWaitTime()); if (me.whoILove().equals(you.getName())) { if (you.whoYouLove().equals(me.getName())) { return true; } else { return false; } } else { return false; } }
/** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Love love = new Love(); Me me = new Me(); me.setName("yt"); me.setWaitTime(2); You you = new You(); you.setName("bh"); /** * 当开始写这段程序时,就已经知道我们之间不是完美的结局,不管多少个if、假设,解决已经注定我们不会在一起, * 打印的语句永远是"缘分不到",除非你改变了注意,修改了属于你的程序 */ if (love.loveResult(me, you)) { System.out.println("我很幸福"); } else { System.out.println("缘分不到"); } }
}
/** * 描述我的类 * @author yongtree * */ class Me extends Person {
int waitTime;
You you = new You();
//这个是返回我爱谁的方法,其实在我的心里我就已经把这个人设定成了你 public String whoILove() { you.setName("bh"); String name = you.getName(); System.out.println("我说:"+name + ",I love you!"); return name; }
public void Miss(String name, int years) { System.out.println("思念是一种幸福!"); if (years < 2) { years = 2;//两年的有期徒刑,呵呵 } for (int i = 0; i < years; i++) { System.out.println(name + ",我每天都想你无法入睡。"); System.out.println("时时刻刻的思念是一种折磨"); // break;好像加上这个break语句,让我从这种痛苦中解脱出来,但是还是忍不住把它注释掉了,依然选择了重复这种折磨 } }
public int getWaitTime() { return waitTime; }
public void setWaitTime(int waitTime) { this.waitTime = waitTime; } } /** * 描述你的类 * @author yongtree * */ class You extends Person { public String whoYouLove() { Other other = new Other(); other.setName("x");// 不知道是谁的名字,只有你清楚。 //很多时候我都想把Other这个对象强制转换成Me,但我知道这样是徒劳的。 String name = other.getName(); System.out.println("你说:"+name + ",I love you!"); return name; }
}
/** * 描述其他人的类 * @author yongtree * */ class Other extends Person {
}
/** * 描述人的类 * @author yongtree * */ class Person { String name;