现在的位置: 首页 > 综合 > 正文

java小银行的完善2.0版(一)

2014年08月31日 ⁄ 综合 ⁄ 共 4512字 ⁄ 字号 评论关闭

其实叫java小银行还不如说是ATM机,不久之前,发表了java小银行1.0版,这次就继续延续此名啦!但ATM其实不存在删除用户这一选项。从功能分析只能说是顾客

自己去注销自己的银行卡。

 

这次新增的4个功能是取款、.存款、查看历史记录、个人电子银行、退卡。并且补好了上面1.0版的漏洞。
取款、.存款这是用户本身的行为,所以直接在java小银行1.0版中的Account加上两个方法既可以了;查看历史,我在此是用了一些数组进行记录的如t[2]记录YEAR

对于个人电子银行就是实现打开建设银行的链接;另外用System.exit(0)模拟退卡。

在其中遇到的问题是:取款、.存款都是在以前的基础上进行的。但下面的已经解决,这个问题上要注意一下。

主类:shiyan10_4

顾客:Account

银行:bank类

 另外的类我发表在java小银行的完善2.0版(二)文章中,本应用程序可能存在漏洞,希望大家帮忙指出。(爱技术,也爱生活。)

知识点:http://docs.oracle.com/javase/6/docs/api/java/awt/Desktop.html

http://jingyan.baidu.com/article/7f766daf7ad5b04100e1d040.html

 主类:shiyan10_4

//MR OU
//java小银行的完善2.0版
//2012,12
public class shiyan10_4 {

	
	public static void main(String[] args) {
		
			    caidan cai=new caidan();
			    Calendar c1=Calendar.getInstance();//系统时间
			    String[] str2=new String[10];//记录历史
			    double[]  t2=new double[10];//记录历史
			    int[]  t3=new int[10];//记录历史
			    int[]  t4=new int[10];//记录历史
			    double[] t5=new double[10];//记录历史
			    bank  b=null;
			    Boolean bl=false;//控制顾客先建立用户才能存取。
			    Scanner sca=new  Scanner(System.in);
			   
			    int i=sca.nextInt();
			    int jishu=0;//控制历史记录的条数,超过十条,取余刷新。
			    String str1=null;
			    Account c=new Account();
		while(true)
		{
			switch(i)
			{
				case 1:str1="中国银行" ; System.out.println(str1+"欢迎您");if(b==null){b=new zhongguobank(str1);};break;
				case 2:str1="建设银行"; System.out.println(str1+"欢迎您");if(b==null){b=new jianshebank(str1);};break;
				case 3:str1="工商银行"; System.out.println(str1+"欢迎您");if(b==null){b=new gongshangbank(str1);};break;
				default:break;
		    }
			System.out.println("1,新建账户");
			System.out.println("2,删除账户");
			System.out.println("3.取款");
			System.out.println("4.存款");
			System.out.println("5.查看历史记录");
			System.out.println("6.个人电子银行");
			System.out.println("7.退卡");
			
			int  t=sca.nextInt();
			switch(t)
			{
				case 1:bl=true;t=1;break;
				case 2:t=2;break;
				case 3:t=3;break;
				case 4:t=4;break;
				case 5:t=5;break;
				case 6:t=6;break;
				case 7:t=7;System.exit(0);;break;
				default:break;
			}
			if(t==1)
			{
			    
				System.out.println("请输入账号:");
				String str=sca.next();
				    c.setAccountlno(str);
			    System.out.println("请输入密码:");
			    String pass=sca.next();
				    c.setPassword(pass);
				System.out.println("请输入存入金额:");
				int money=sca.nextInt();
				c.setMoney(money);
		        {
					b.newAccount(c);
			    }
			}
			if(t==2)
			{
				if(bl==true)
				{
				System.out.println("请输入删除第几个账户");
				int j=sca.nextInt();
				b.deleteAccount(j-1);
			    }
				else
				{
					System.out.println("亲!先新建账户啊!");
					
				}
			}
			if(t==3)
			{
				if(bl==true)
				{
					System.out.println("请输入取款金额:");
					double drawmoney=sca.nextDouble();
					double t1=c.withdraw(drawmoney);
					if(t1<0)
					{
						System.out.println("亲!你的余额不足!"); 	
					}
					else
					{
						  
					        System.out.println("你的"+str1+"还剩"+t1);
					     if(jishu<10)
					        {
						        t2[jishu]=c1.get(Calendar.YEAR);
						        t3[jishu]=c1.get(Calendar.MONTH)+1;
						        t4[jishu]=c1.get(Calendar.DAY_OF_MONTH);
						        str2[jishu]="你的建设银行取款";
						        t5[jishu]=drawmoney;
						        jishu=jishu+1; 
					        }
					     else
					     {
					    	 jishu=jishu%10;
					     }
					}
				}
				else
				{
					System.out.println("亲!先新建账户啊!才能取款啊!");
					
				}
				
			}
			
			if(t==4)
			{
				if(bl==true)
				{
					System.out.println("请输入存款金额:");
					double  savingmoney1=sca.nextDouble();
				    System.out.println("存入成功!");
				    System.out.println("你的卡上金额为:"+c.savingdraw(savingmoney1));
				    if(jishu<10)
				    { 
				    t2[jishu]=c1.get(Calendar.YEAR);
			        t3[ jishu]=c1.get(Calendar.MONTH)+1;
			        
			        t4[jishu]=c1.get(Calendar.DAY_OF_MONTH);
			        str2[jishu]="你的建设银行取款";
			        t5[jishu]=savingmoney1;
			        jishu=jishu+1;
				    }
				    else
				    {
				    	jishu=jishu%10;
				    	
				    }
					
				}
				else
				{
					System.out.println("亲!先新建账户啊!才能存款啊!");
				       
				}
			}
			if(t==5)
			{
				for( i=0;i<jishu;i++)
				
					{
					
	 				   	  System.out.print(t2[i]+"年"+t3[i]+"月"+t4[i]+"日");
					      System.out.print(str2[i]);
					      System.out.println(t5[i]);
					}
				
			}
			if(t==6)
			{
				URI  uri;
			try
			{
				uri=new URI("http://www.ccb.com/cn/home/index.html");
				Desktop dtp=Desktop.getDesktop();
				if(Desktop.isDesktopSupported())
				{
					dtp.browse(uri);
				}
			}catch(Exception e)	
			{
				System.out.println(e);
			}
				
				
			}
	  }   
	}

	
}

顾客:Account顾客:Account顾客类

class Account 
{
	    String	Accountlno;
	    private  String  password;
	    private static double  money;
	   
		public String getAccountlno() {
			return Accountlno;
		}
		public void setAccountlno(String accountlno) {
			Accountlno = accountlno;
		}
		public String getPassword() {
			return password;
		}
		public void setPassword(String password) {
			this.password = password;
		}
		public static double getMoney() {
			return money;
		}
		public void setMoney(double money) {
			this.money = money;
		}
		public  double withdraw( double withdrawmoney)//取款(int/贪心算法)
		{   
			//System.out.println(getMoney());
			money=getMoney()-withdrawmoney;
			return  money;
		
		}
		public  double savingdraw(double savingdrawmoney)//存款(int/贪心算法)
		{
			money=getMoney()+savingdrawmoney;
		
			//System.out.println(getMoney());
			return  money;
		}
          
}

 

银行类

class  bank
{
	      String  name;
		 LinkedList<Account> a1=new   LinkedList<Account>();
		public bank(String  name)
		{
			this.name=name;
		}
		public void newAccount(Account a)
		{
			
			a1.add(a);
			
			System.out.println("第"+a1.size()+"帐户新建成功!");
			Iterator<Account> iter=a1.iterator();
			while(iter.hasNext())
			{
				Account  a2=iter.next();
				System.out.println("账号"+"     "+"密码"+"   "+"金额");
				System.out.println(a2.getAccountlno()+"   "+a2.getPassword()+"   "+a2.getMoney());
				
			}
		}
		public void deleteAccount(int j)
		{
			
			if(a1.size()==0)
			{
			  System.out.println("没有账户!删除不成功!");	
			}
			else
			{
				a1.remove(j);
			    System.out.println("删除了第"+(j+1)+"账户成功");
			}
		}
}

 

 

 

抱歉!评论已关闭.