语句就是Boy boy1=new boy("name",age,height,true,true)
解决方案 »
- 一个关于 多分支选择 的问题~~
- 请教各位前辈,在什么情况下你会自然地使用JAVA的多态
- 一个初学boolean容易忽视的问题。
- netbeans里如何输入命令行参数
- 如何取得一段时间里的连续时间串
- 一个课后题:写一个程序,可以从C盘找出一个文件所在的路径
- 请叫各位大虾一下,我想在JComboBox中对对应的每一条在添加一个隐藏的值
- 推荐一本JAVA2图形设计卷2(SWING)
- 请问用j2sdkee的depoly工具部署之后的文件放在什么目录下?
- 如何将java.util.Date转化为java.sql.Date?数据库中Date类型对应于java的哪个Date呢
- 请帮我找找错误,谢谢!
- 初学者关于多线程的一个问题
具体怎么弄呢不懂。。请指点下。。
public static void main(String[] args) throws IOException {
class Boy{ public Boy(String string, int age, int height, boolean b, boolean c) {
// TODO Auto-generated constructor stub
}
}
int age = 0;
int height = 10;
Boy boy1=new Boy("name",age,height,true,true);
}
public class Lovestory1
{
public interface CompusMateStandard
{
public boolean isLike(Human human);
}
public interface SocietyMateStandard
{
public boolean isLove(Human human);
}
class CompusGfStandard implements CompusMateStandard
{
boolean isKind_Hearted=true;
boolean isBeauty=true;
boolean isThoughtful=true;
public boolean isLike(Human human)
{
if(human instanceof Girl)
{
Girl girl=(Girl) human;
if(girl.isKind_Hearted==this.isKind_Hearted&&girl.isBeauty==this.isBeauty&&girl.isThoughtful==this.isThoughtful)
return true;
else {System.out.println("告诉自己:这个女孩并不适合你,那个人还在未来的路口等你");return false;}
}
else {System.out.println("不能有背背山。。");return false;}
}
}
class CompusBfStandard implements CompusMateStandard
{
boolean isCute=true;
boolean isRomantic=true;
int minHeight=175;
public boolean isLike(Human human)
{
if(human instanceof Boy)
{
Boy boy=(Boy) human;
if(boy.isCute==this.isCute&&boy.isRomantic==this.isRomantic&&boy.height>this.minHeight)
return true;
else {System.out.println("女孩说:我不适合你,你会找到比我更好的");}
}
else {System.out.println("女孩沉默。。然后逃跑。。");return false;}
}
}
class SocietyGfStandard implements SocietyMateStandard
{
boolean isKind_Hearted=true;
boolean isSunshine=true;
public boolean isLove(Human human)
{
if(human instanceof Woman)
{
Woman woman=(Woman) human;
if(woman.isKind_Hearted==this.isKind_Hearted&&woman.isSunshine==this.isSunshine)
return true;
else return false;
}
}
}
class SocietyBfStandard implements SocietyMateStandard
{
boolean isSober=true;
boolean isResponsibility=true;
boolean isHaveGodJob=true;
public boolean isLove(Human human)
{
if(human instanceof Man)
{
Man man=(Man) human;
if(man.isSober==this.isSober&&man.isResponsibility==this.isResponsibility&&man.haveGodJob()==this.isHaveGodJob)
return true;
return false;
}
}
}
public class Human
{
String name;
int age;
int height;
public Human(String name,int age,int height)
{
this.name=name;
this.age=age;
this.height=height;
}
}
public class Boy extends Human
{
boolean isCute=false;
boolean isRomantic=false;
CompusGfStandard gfStandard=new CompusGfStandard();
Girl girlfriend;
Girl unrequitedGirl;
public Boy(String name,int age,int height,boolean isCute,boolean isRomantic)
{
super(name,age,height);
this.isCute=isCute;
this.isRomantic=isRomantic;
}
public boolean isMygirl(Girl girl)
{
if(gfStandard.isLike(girl))
return true;
return false;
}
public boolean showLove(Girl girl)
{
if(girl.isAccept(this))
{
girlfriend=girl;
return true;
}
return false;
}
public boolean unrequitedLove(Girl girl)
{
if(gfStandard.isLike(girl))
unrequitedGirl=girl;
}
}
public class Girl extends Human
{
boolean isKind_Hearted=false;
boolean isBeauty=false;
boolean isThoughtful=false;
CompusBfStandard bfStandard=new CompusBfStandard();
Boy boyfriend;
public Girl(String name,int age,int height,boolean isKind_Hearted,boolean isBeauty,boolean isThoughtful)
{
super(name,age,height);
this.isKind_Hearted=isKind_Hearted;
this.isBeauty=isBeauty;
this.isThoughtful=isThoughtful;
}
boolean isAccept(Boy boy)
{
if(this.bfStandard.isLike(boy))
{
boyfriend=boy;
return true;
}
return false;
}
}
public class Man extends Boy
{
boolean isSober=false;
boolean isResponsibility=false;
boolean isCapable=false;
SocietyGfStandard gfStandard=new SocietyGfStandard();
public Man(String name,int age,int height,boolean isSober,boolean isResponsibility,boolean isCapable)
{
super(name,age,height,true,true);
this.isSober=isSober;
this.isResponsibility=isResponsibility;
this.isCapable=isCapable;
}
public boolean showLove(Girl girl)
{
if(girl.isAccept(this))
{
girlfriend=girl;
}
return false;
}
boolean haveGodJob()
{
if(this.isCapable) return true;
return false;
}
}
public class Woman extends Girl
{
boolean isSunshine=false;
SocietyBfStandard bfStandard=new SocietyBfStandard();
public Woman(String name,int age,int height,boolean isKind_Hearted,boolean isBeauty,boolean isThoughtful, boolean isSunshine)
{
super(name,age,height,isKind_Hearted,isBeauty,isThoughtful);
this.isSunshine=isSunshine;
}
boolean isAccept(Man man)
{
if(this.bfStandard.isLove(man))
{
boyfriend=man;
return true;
}
return false;
}
boolean isStillLove(Man man)
{
if(man.haveGodJob()) return true;
else return false;
}
}
public static void main(String[] args)
{
System.out.println("This is a love story");
System.out.println("The story take place in a famous school called Cambridge");
System.out.println("The hero of this story named Xuzhimo and the heroine named Linhuiyin");
System.out.println("The story starts in their first year on compus.That year,they were eighteen");
Boy Xuzhimo=new Boy();
Girl Linhuiyin=new Girl();
if(Xuzhimo.isMygirl(Linhuiyin))
System.out.println("One day and occasional,he met her.Afterwards he was crazy about her");
if(Xuzhimo.unrequitedLove(Linhuiyin))
System.out.println("He could'nt sleep at night,all memories was her,then he decided to vindicate");
if(Xuzhimo.showLove(Linhuiyin))
System.out.println("Linhuiyin accepted her,and a romantic love begun");
System.out.println("Xuzhimo is a very talent guy and compose many love poem.Zaibiekangqiao was a popular one of them");
System.out.println("But good time always flies that would'nt weak you when you still enjoy it.");
System.out.println("Four years later ,they had to make choices.To go on their relationship or apart");
System.out.println("For Linhuiyin,she had much to think,she need a reliable man can give her a stable life");
Man Xuzhimo1=(Man) Xuzhimo;
Xuzhimo1.isSober=true;Xuzhimo1.isResponsibility=true;Xuzhimo1.isCapable=false;
Woman Linhuiyin1=(Woman) Linhuiyin;
Linhuiyin1.isSunshine=false;
if(!Linhuiyin1.isStillLove(Xuzhimo1))
System.out.println("Linhuiyin finally leave Xuzhimo because of the real world pressure");
System.out.println("Not long after,another man appear in her world.His name is Liangsicheng");
Man Liangsicheng=new Man();
if(Liangsicheng.showLove(Linhuiyin1))
System.out.println("They fall in love with each other crazielly,and the have a happy life");
}
}
还有,我感觉LZ在写这个代码是不是完全用记事本写的?
不用编译器吗?
Main方法是静态方法,在它里面要想实例化非静态的内部类
必须要有一个实例,否则就把内部类整成静态的
Lovestory1 l=new Lovestory1 ();
Lovestory1.Boy boy=l.new Boy();
改为
语句就是Boy boy1=new Boy("name",age,height,true,true)
即可