求高手来解答个
package Bank;
//Create New Class BankAccount
public class BankAccount {
private long accountNum;
private long passWord;
private String name;
private long ID;
private long balance;
public BankAccount(){
this.balance=0;
}
//public BankAccount(long a,long p,String n,long ID,long b){
//this.accountNum=a;
//this.passWord=p;
//this.name=n;
//this.ID=ID;
//this.balance=b;
//}
public long getAccountNum(){
return this.accountNum;
}
public long getPassWord(){
return this.passWord;
}
public String getName(){
return this.name;
}
public long getID(){
return this.ID;
}
public long getBalance(){
return this.balance;
}
public void setAccountNum(long a){
this.accountNum=a;
}
public void setPassWord(long p){
this.passWord=p;
}
public void setName(String n){
this.name=n;
}
public void setID(long ID){
this.ID=ID;
}
public void setBalance(long b){
this.balance=b;
}
public boolean comparePassWord(long i,long j){
if(i==j)
return true;
else
return false;
}
public void printIfo(){
System.out.println("AccountNumber: "+getAccountNum()+"\nName: "+getName()+"\nBalance: "+getBalance());
}
}
package Bank;
//Operations of Bank
import java.util.Scanner;
public class BankMethods{
BankAccount acc=new BankAccount();
Scanner input=new Scanner(System.in);
long accountNum,passWord,ID,balance;
String name;
//注册
public void Register(){
//用户名
System.out.println("Input Your Account Number: ");
accountNum=input.nextLong();
boolean flag=true;
while(flag){
if((accountNum>=1*Math.pow(10,16))||(accountNum<1*Math.pow(10,15))){
System.out.println("Wrong Accounmt number, input again: ");
Scanner input=new Scanner(System.in);
accountNum=input.nextLong();
flag=true;
}
else{
acc.setAccountNum(accountNum);
System.out.println("AccountNumber Aviliable.");
flag=false;
}
}
//设置密码
System.out.println("Input Your PassWord: ");
passWord=input.nextLong();
boolean flag1=true;
while(flag1){
if((passWord>=1*Math.pow(10,6))||(passWord<1*Math.pow(10,5))){
System.out.println("Wrong Number, input again: ");
Scanner input=new Scanner(System.in);
passWord=input.nextLong();
flag1=true;
}
else{
System.out.println("Input Your PassWord Again: ");
long passWord1=input.nextLong();
if(passWord1!=passWord){
System.out.println("Wrong Number, input again: ");
passWord=input.nextLong();
flag1=true;
}
else{
acc.setPassWord(passWord);
System.out.println("passWord Aviliable.");
flag1=false;
}
}
}
//开户人姓名
System.out.println("Input Your Name: ");
name=input.next();
acc.setName(name);
//身份证号码
System.out.println("Input Your ID: ");
ID=input.nextLong();
boolean flag2=true;
while(flag2){
if((ID>=1*Math.pow(10,18))||(ID<1*Math.pow(10,17))){
System.out.println("Wrong ID NUmber, input again: ");
Scanner input=new Scanner(System.in);
this.ID=input.nextLong();
flag2=true;
}
else{
acc.setID(ID);
System.out.println("ID Avilliable.");
flag2=false;
System.out.println("Registration Successed");
Login();
}
}
System.exit(1);
}
//登录
public boolean Login(){
boolean flag=false;
boolean flag1=true;
System.out.println("Login: ");
while(flag1){
System.out.println("Input Your Account Number: ");
accountNum=input.nextLong();
if(accountNum==(acc.getAccountNum())){
flag1=false;
boolean flag2=true;
while(flag2){
System.out.println("Input Your PasWord: ");
passWord=input.nextLong();
if(passWord==(acc.getPassWord())){
System.out.println("Progressing, Please wait...");
flag=true;
flag2=false;
}
else{
System.out.println("Wrong PasssWord, Input Again: ");
flag2=true;
}
}
}
else{
System.out.println("Error: Account Does not exits. Input again: ");
flag1=true;
}
}
return flag;
}
//取款
public void Withdrawals(){
if(Login()){
System.out.println("Input The Amount You want to Withdrawals: ");
int money=input.nextInt();
balance-=money;
if(balance<0){
System.out.println("You Don't Have Enough Money In this Account, Try Annother Amount.");
}
else{
acc.setBalance(balance);
System.out.println("Progressing, Please Wait...");
System.out.println("You Got "+balance+" Left In Your Account.");
}
}
}
//存款
public void Deposit(){
if(Login()){
System.out.println("Input The Amount You Want To Deposit: ");
int money=input.nextInt();
balance+=money;
acc.setBalance(balance);
System.out.println("Deposit Successed, You Got "+balance+" Left In Your Account.");
}
}
//转账
public void transfer(){
if(Login()){
System.out.println("Input The Account You Want To Transfer To:");
long account=input.nextLong();
boolean flag=true;
while(flag){
if((account>=1*Math.pow(10,17))||(account<1*Math.pow(10,16))){
System.out.println("Wrong Accounmt number, input again: ");
Scanner input=new Scanner(System.in);
account=input.nextLong();
flag=true;
}
else{
System.out.println("Input The Account Again:");
long account1=input.nextLong();
if(account1!=account){
System.out.println("Wrong Account NUmber, Input Again:");
account=input.nextLong();
flag=true;
}
else{
System.out.println("Input The Amount You Want To Transfer: ");
int money=input.nextInt();
balance-=money;
acc.setBalance(balance);
System.out.println("Transfer Successed, You Got "+balance+"Left In Your Account.");
}
}
}
}
}
//用户信息
public void Infor(){
if(Login()){
acc.printIfo();
}
}
//修改密码
public void ChangePassWord(){
if(Login()){
System.out.println("Input Your New PassWord: ");
passWord=input.nextLong();
boolean flag=true;
while(flag){
if((passWord>=1*Math.pow(10,7))||(passWord<1*Math.pow(10,6))){
System.out.println("Wrong Number, input again: ");
Scanner input=new Scanner(System.in);
passWord=input.nextLong();
flag=true;
}
else{
System.out.println("Input Your New PassWord Again: ");
long passWord1=input.nextLong();
if(passWord1!=passWord){
System.out.println("Wrong Number, input again: ");
passWord=input.nextLong();
flag=true;
}
else{
acc.setPassWord(passWord);
System.out.println("Change Successed.");
flag=false;
}
}
}
}
}
}
package Bank;
//Operations of Bank
import java.util.Scanner;
public class BankOperation {
Scanner input=new Scanner(System.in);
BankMethods method=new BankMethods();
void begin(){
System.out.println("请登录,若还没有账号请先行注册:");
System.out.println("---1---\t---注册---");
System.out.println("---2---\t---登录---");
System.out.println("---0---\t---退出---");
int i=input.nextInt();
switch(i){
case 1:method.Register();break;
case 2:method.Login();break;
case 0:System.exit(1);break;
default:System.out.println("输入有误,请重新输入。");
}
if(method.Login()){
while(true){
System.out.println("您可以进行以下操作:");
System.out.println("---1---\t---取款---");
System.out.println("---2---\t---存款---");
System.out.println("---3---\t---转账---");
System.out.println("---4---\t---查询信息---");
System.out.println("---5---\t---更改密码---");
System.out.println("---0---\t---退出---");
int k=input.nextInt();
switch(k){
case 1:method.Withdrawals();break;
case 2:method.Deposit();break;
case 3:method.transfer();break;
case 4:method.Infor();break;
case 5:method.ChangePassWord();break;
case 0:System.exit(1);
default:System.out.println("Input Error.");
}
}
}
}
}
package Bank;
//Test Bank
public class BankTest {
public static void main(String[] args){
BankOperation bank=new BankOperation();
bank.begin();
}
}