1. 程式人生 > >銀行賬戶管理

銀行賬戶管理

println 賬戶管理 bool input name png else i++ AS

實驗結果

技術分享圖片

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+"\nAccountID "+this.accountID+"\nID: "+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();


}
}

銀行賬戶管理