通过实例了解接口的含义

王朝java/jsp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

今天试着写一个简单的银行存储小程序,只是一个内核思路而已,如果要完成所有功能,那还需要逐渐来完善的,代码如下:

public class test

{

public static void main(String args[])

{

boolean blue=false;

float money=0.00f;

String xx;

demo impl=new demo();

blue=impl.regname("wenyu1314",12,8000.0f);

if(blue)

{

System.out.println("Good luck! you have 8000$\n");

System.out.println("UserName: "+impl.username);

System.out.println("UserID: "+impl.userid);

System.out.println("Money: "+impl.money);

System.out.println("-----------------------------------------------------------");

}

else

System.out.println("Sorry!! this is system's worng");

blue=impl.depost(500);

if(blue)

System.out.println("Good luck!");

else

System.out.println("Sorry!! this is system's worng1");

money=impl.retive(12,20.0f);

if(money!=0.0f)

{

System.out.println("Good luck!");

System.out.println("You have money is : "+impl.money);

}

else

System.out.println("Sorry!! this is system's worng2");

float money1=0.0f;

blue=impl.getuserid(12);

if(blue)

System.out.println("OK! you ID is money : "+impl.money);

else

System.out.println("Sorry is not this userid");

}

}

interface conner

{

boolean regname(String username,int userid,float money);

boolean depost(float money);

float retive(int userid,float money);

boolean getuserid(int userid);

}

class demo implements conner

{

String username;

int userid;

float money;

public demo(){};

public demo(String username,int userid,float money)

{

this.username=username;

this.userid=userid;

this.money=money;

}

public boolean regname(String username,int userid,float money)

{

this.username=username;

this.userid=userid;

this.money=money;

return true;

}

public float retive(int userid,float money)

{

if(userid==this.userid)

return money;

else

return 0.00f;

}

public boolean depost(float money)

{

this.money+=money;

return true;

}

public boolean getuserid(int userid)

{

if(userid==this.userid)

return true;

else

return false;

}

}

听一位高手说,接口用处很多,写程序离不开接口,所以记录下来以防日后忘了^_^

通过今天写的这个小程序还明白了数据库存储数据大部分是通过数组的

也不知道哪根筋想到的,嘿嘿...

有时间写一个小型的数据库

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航