您的位置:首页 > 其它

通过实例了解接口的含义

2005-03-09 21:14 375 查看
今天试着写一个简单的银行存储小程序,只是一个内核思路而已,如果要完成所有功能,那还需要逐渐来完善的,代码如下:
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;
}
}

听一位高手说,接口用处很多,写程序离不开接口,所以记录下来以防日后忘了^_^
通过今天写的这个小程序还明白了数据库存储数据大部分是通过数组的
也不知道哪根筋想到的,嘿嘿...
有时间写一个小型的数据库
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: