通过实例了解接口的含义
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;
}
}
听一位高手说,接口用处很多,写程序离不开接口,所以记录下来以防日后忘了^_^
通过今天写的这个小程序还明白了数据库存储数据大部分是通过数组的
也不知道哪根筋想到的,嘿嘿...
有时间写一个小型的数据库
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;
}
}
听一位高手说,接口用处很多,写程序离不开接口,所以记录下来以防日后忘了^_^
通过今天写的这个小程序还明白了数据库存储数据大部分是通过数组的
也不知道哪根筋想到的,嘿嘿...
有时间写一个小型的数据库
相关文章推荐
- 实现Runnable接口的类+使用Thread类的实例来创建线程---->通过实现Runnable接口来创建线程类
- java通过Comparable接口实现字符串比较大小排序的简单实例
- 通过一个简单的AJAX实例,了解其大致步骤
- 通过生活中例子模拟java面向接口编程实例
- 通过生活中例子模拟java面向接口编程实例
- 本章通过先总体介绍UICollectionView及其常用方法,再结合一个实例,了解如何使用UICollectionView
- Spring Boot 实例代码之通过接口安全退出
- 怎么生成内部hide接口实例并通过反射作为参数进行传递
- 通过实例了解抽象工厂(二)数据层
- GTP协议循序渐进(三)----通过实例了解TEID
- 通过实例来了解PHP中的persistent resource和non persistent resource
- Java通过接口实现匿名类的实例
- 通过实例了解如何使用js获取下拉列表框内的值
- 读写锁接口实例-通过ReadWriteLock实现一个简单的缓存
- Java通过接口实现匿名类的实例代码
- Hadoop - Map/Reduce 通过WordCount例子的变化来了解新版hadoop接口的变化
- GTP协议循序渐进(三)----通过实例了解TEID
- C#基础:通过一个实例来学习IFormattable接口,扩展方法
- C#基础:通过一个实例来学习IFormattable接口,扩展方法
- 3.通过AES加密实例(基于c和oc)进一步了解指针