中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > 编程语言 > Java > 综合文章
通过实例了解接口的含义
作者:未知 时间:2005-07-27 22:27 出处:CSDN 责编:chinaitpower
              摘要:通过实例了解接口的含义
今天试着写一个简单的银行存储小程序,只是一个内核思路而已,如果要完成所有功能,那还需要逐渐来完善的,代码如下:
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;
 }
}

听一位高手说,接口用处很多,写程序离不开接口,所以记录下来以防日后忘了^_^
通过今天写的这个小程序还明白了数据库存储数据大部分是通过数组的
也不知道哪根筋想到的,嘿嘿...
有时间写一个小型的数据库
关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有