• 银行账户管理


    实验结果

    package 类的继承;

     import java.util.Scanner; 
     import java.math.*; 
     class Account{ 
         String name; 
         static int count=0; 
         static String[] opea=new String[100000]; 
         static double[] val=new double[1000]; 
         double balance; 
         static  String accountID="1234567891011121314"; 
         String id; 
         public Account(String name,double balance,String id){ 
             this.set(name,balance,id); 
         } 
         public void set(String name,double balance,String id){ 
             this.name=name; 
             this.balance=balance; 
             if(id.length()>18||id.length()<1){ 
                 System.out.println("Input ID Error !"); 
                 return ; 
             } 
             this.id=id; 
             accountID=add(accountID); 
         } 
         public void inquire(){ 
             System.out.println("-------账户余额信息 -------"); 
             System.out.println("balance : "+this.balance); 
             for(int i=0;i<count;i++){ 
                 System.out.println(opea[i]+" "+val[i]); 
             } 
         } 
         public String getName(){ 
             return "AccoutName : "+this.name+" AccountID "+this.accountID+" ID: "+id.substring(0,6)+"********"+id.substring(14,id.length()); 
         } 
         public double balance(){ 
             return this.balance; 
         } 
         public boolean put(double value){ 
             this.balance+=value; 
             if(value==0){ 
                 return false; 
             } 
             opea[count]="put"; 
             val[count++]=value; 
             return true; 
         } 
         public double get(double value){ 
             if(value>this.balance){ 
                 System.out.println("lack of balance !!!"); 
                 return 0; 
             } 
             opea[count]="get"; 
             val[count++]=value; 
             this.balance-=value; 
             return value; 
         } 
         public boolean exit(){ 
             return true; 
         } 
         public static String add(String str){ 
                 char[] c=new char[19]; 
                 int leng=19; 
                 int sign=0,i; 
                 for(i=0;i<19;i++){ 
                     leng=leng-1; 
                     int sum=0; 
                     sum+=str.charAt(leng)-'0'; 
                     if(i==0){ 
                         sum+=1; 
                     } 
                     sum+=sign; 
                     c[leng]=(char)(sum+48); 
                     if(sum>=10){ 
                         sign=1; 
                         c[leng]=(char)(sum%10+48); 
                     }else{ 
                         sign=0; 
                     } 
                 } 
                 return String.valueOf(c); 
         } 
     } 
     

    package 类的继承;
    class Main{ 
        public static void main(String[] args){ 
            Account p=new Account("infinite",4000,"1111111111111111"); 
            System.out.println("-------账户信息-------"); 
            System.out.printf(p.getName()); 
            System.out.println(); 
            System.out.println("balance : "+p.balance()); 
            p.put(153213); 
            p.inquire(); 
            System.out.println(); 
             
           
        } 

  • 相关阅读:
    Mybatis中javaType和jdbcType对应关系
    spy日志
    mybatis批量插入和更新
    js打印方案
    js弹窗,父子窗口调用
    extjs4.1
    oracle开启远程连接访问
    javaweb打印
    Leetcode 392.判断子序列
    Leetcode 391.完美矩形
  • 原文地址:https://www.cnblogs.com/infinite14/p/8965143.html
Copyright © 2020-2023  润新知