2020-11-24

银行管理系统2.0(java)

创建一个Bank包

创建Admin类

package Bank;

import Bank.Bank;

public class BankTest {
	
	public static void main(String[] args) {
		
		//银行对象
		Bank bk = new Bank("中国招商银行");
		
		//银行工具类
		BankUtils bkUtils = new BankUtils();
		
		//拿到模拟数据
		DataBase db = new DataBase();
		Admin [] admins = db.getAdmin();
		Customer[] customers = db.getCostomer();
		
		//银行管理系统管理员功能封装
		BankSysMethod bkSysMethod = new BankSysMethod();
		
		//银行管理系统用户功能封装
		BankCustomerMethod bkCustomerMethod = new BankCustomerMethod();
		
		//存储登陆的管理员
		Admin admin = null;
		
		//存储登陆的用户
		Customer customer = null;
		
		//判断是否退出
		Boolean isExit = true;
		do {
			//登陆界面
			 System.out.println("Welcome to the use "+bk.getName()+"系统,请根据你的需求选择你需要的操作");
			 System.out.println("***************	请选择:	1.管理员登陆 	2.用户登陆		3.退出	***************");
			 
			 //获取输入的   int 类型的值
			 int selectMenu = bkUtils.getReadInt();
			 switch (selectMenu) {
			case 1:
				//1、管理员登陆验证,并把登陆的管理员返回
				 admin = bkSysMethod.sysRootDengLu(admins);
				 if(admin == null) {
						return;
					}
				System.out.println(admin);
				bkSysMethod.sysRootMethod(customers);
				break;
			case 2:
				customer = bkCustomerMethod.sysCustomerDengLu(customers);
				if(customer == null) {
					return;
				}
				bkCustomerMethod.bankCustomerMethod(customer);
				System.out.println("用户登陆成功");
				break;
			case 3:
				isExit = false;
				System.out.println("退出成功");
				break;
			default:
				System.out.println("你的输入有误,请重新输入!!!");
				break;
			}
			 
		} while (isExit);
	}

}

创建Bank类

package Bank;

public class Bank {
	
	private String name;//银行名
	private String cardNum;//银行卡号
	
	
	public Bank(String name) {
		this.name = name;
	}
	public Bank() {
		super();
	}
	public Bank(String name, String cardNum) {
		super();
		this.name = name;
		this.cardNum = cardNum;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getCardNum() {
		return cardNum;
	}
	public void setCardNum(String cardNum) {
		this.cardNum = cardNum;
	}

}

创建BankCustomerMethod类

package Bank;

import Bank.Customer;

public class BankCustomerMethod {
	
	
	BankUtils bkUtils = new BankUtils();
	
	Customer cust = new Customer();
	
	/**
	 * 
	 * 本方法整合用户的 功能实现 1.存钱	2.取钱	3.修改密码    4.查看个人信息    5.返回上一级
	 * 	
	 * 		@param 把登陆的用户对象传进来
	 */
	public void bankCustomerMethod(Customer customer) {
		boolean isExit = true;
		while(isExit) {
			System.out.println("请选择你需要进行的操作:1.存钱	2.取钱	3.修改密码    4.查看个人信息    5.返回上一级");
			int customerSelect = bkUtils.getReadInt();
			switch (customerSelect) {
			case 1:
					//1.存钱
				 System.out.println("存钱");
				cust.addMoney(customer);
				break;
				
			case 2:
					//2.取钱
				 System.out.println("取钱");
				cust.deleteMoney(customer);
			break;
			
			case 3:
				//3.修改密码
				 System.out.println("修改密码");
				cust.updaterCustomerPsd(customer);
			break;
			
			case 4:
				//查看个人信息
				 System.out.println("查看个人信息");
				cust.displayCustomer(customer);
			break;
			
			case 5:
				System.out.println("返回上一级");
				isExit = false;
			break;

			default:
				System.out.println("系统操作错误!!!");
				break;
			}
		}
		//return customer;
	}

		
	
	public Customer sysCustomerDengLu(Customer [] customers) {
		for(int x  = 1 ; x <= 3 ; x++) {
			
			//获取输入的用户账号
			System.out.println("请输入用户账号:");
			String account = bkUtils.getReadString();
			//获取输入的用户密码
			System.out.println("请输入用户密码:");
			String psd = bkUtils.getReadString();
			
			/*
			 * 循环遍历所有管理员账号,密码;
			 * 		如果输入的管理员账号存在,则用verificatAccount存储账号
			 * 		如果输入的管理员账号密码,则用verificatPsd存储密码
			 * 并把该对象返回 ,使用admin存储
			 */
			String verificatAccount = null;
			String verificatPsd = null;
			Customer customer = null ;
			for(int y = 0 ; y < customers.length; y++) {
					if(customers[y].getAccount().equals(account)) {
						verificatAccount = customers[y].getAccount();
						verificatPsd = customers[y].getPassword();
						customer = customers[y];
						break;
					}
			}
			
			/*
			 * 如果verificatAccount和verificatPsd为null
			 * 		都为null:则说明输入的管理员账号,密码不存在,显示该管理员不存在提示
			 * 		verificatAccount为null:则说明输入的管理员账号不存在,显示该管理员账号不存在提示
			 * 		verificatPsd为null:则说明输入的管理员密码不存在,显示该管理员密码错误提示
			 */
			
			if(verificatAccount == null) {
				System.out.println("该用户账号不存在!!!你还有"+(3-x)+"次机会!");
			}else if(!verificatPsd.equals(psd)) {
				System.out.println("用户密码错误!!!你还有"+(3-x)+"次机会!");
			}else if(verificatAccount != null && verificatPsd != null) {
				System.out.println("登陆成功");
				return customer;
			}
			
			//登陆失败只限3次,3次之后冻结
			if((3-x) == 0) {
				System.out.println("你已被冻结,请联系老师解决。");
			}
		}
			return null;
	}
		
}

BankSysMethod类

package Bank;

import Bank.BankUtils;
import Bank.Customer;




public class BankSysMethod {
	
	BankUtils bkUtils = new BankUtils() ;
	
	//存储登陆的管理员
	Admin admin = null ;
	/**
	 * 此方法用于管理员登陆,整合了账号,密码验证方法
	 * @return true 登陆成功  | false 登陆失败
	 */
	public Admin sysRootDengLu(Admin [] admins) {
		for(int x  = 1 ; x <= 3 ; x++) {
			
			//获取输入的管理员账号
			System.out.println("请输入管理员账号:");
			String account = bkUtils.getReadString();
			//获取输入的管理员密码
			System.out.println("请输入管理员密码:");
			@SuppressWarnings("unused")
			String psd = bkUtils.getReadString();
			
			/*
			 * 循环遍历所有管理员账号,密码;
			 * 		如果输入的管理员账号存在,则用verificatAccount存储账号
			 * 		如果输入的管理员账号密码,则用verificatPsd存储密码
			 * 并把该对象返回 ,使用成员变量admin存储
			 */
			String verificatAccount = null;
			String verificatPsd = null;
			for(int y = 0 ; y < admins.length; y++) {
					if(admins[y].getAccount().equals(account)) {
						verificatAccount = admins[y].getAccount();
						verificatPsd = admins[y].getPassword();
						admin = admins[y];
						break;
					}
			}
			
			/*
			 * 如果verificatAccount和verificatPsd为null
			 * 		都为null:则说明输入的管理员账号,密码不存在,显示该管理员不存在提示
			 * 		verificatAccount为null:则说明输入的管理员账号不存在,显示该管理员账号不存在提示
			 * 		verificatPsd为null:则说明输入的管理员密码不存在,显示该管理员密码错误提示
			 */
			
			if(verificatAccount == null) {
				System.out.println("该管理员账号不存在!!!你还有"+(3-x)+"次机会!");
			}else if(!psd.equals(verificatPsd)) {
				System.out.println("管理员密码错误!!!你还有"+(3-x)+"次机会!");
			}else if(verificatAccount != null && verificatPsd != null) {
				System.out.println("登陆成功");
				return admin;
			}
			
			//登陆失败只限3次,3次之后冻结
			if((3-x) == 0) {
				System.out.println("你已被冻结,请联系老师解决。");
			}
		}
			return null;
	}
	
	
	
	
	
	//关于Customer的操作方法都存储在Customer类,通过创建Customer对象来调用
	Customer cust = new Customer();
	
	/**
	 * 此方法用于对管理员功能的总的整合
	 * 
	 */
	public void  sysRootMethod(Customer [] customers) {
		
			boolean isExit = true; 
			while(isExit) {
				System.out.println();
				System.out.println("请选择你需要进行的操作:1.查看用户信息	2.修改用户信息	3.增加用户    4.删除用户    5.返回上一级");
				int sysMenu = bkUtils.getReadInt();
				switch (sysMenu) {
				case 1:
					//查看用户信息
					System.out.println("查看用户信息");
					cust.printAllCustomer(customers);
					
					break;
				case 2:
					//修改用户信息
					System.out.println("修改用户信息");
					cust.updateUser(customers);
					break;
				case 3:
					//增加用户
					System.out.println("增加用户信息");
					Customer[] newCustomers = cust.addCustomer(customers);
					//这里的查询用户传进的是Customer[] customer ,所以需要把把扩容后添加进新用户的数组赋值给customer;
					customers = newCustomers;
					break;
				case 4:
					//删除用户 [1,2,3,4,5]   [1,2,null,4,5] -- [,1,2,4,null,5] -- [1,2,3,4,null] .length - 2
					System.out.println("删除用户");
					Customer[] deleteCustomer = cust.deleteCustomer(customers);
					//这里的查询用户传进的是Customer[] customer ,所以需要把减容后的新用户的数组赋值给customer;
					customers = deleteCustomer;
					break;
				case 5:
					isExit = false;
					break;

				default:
					System.out.println("系统操作错误!!!");
					break;
				}
			}
			//return customer;
	}
	
	
	
	

			
}

BankTest类

package Bank;

import Bank.Bank;

public class BankTest {
	
	public static void main(String[] args) {
		
		//银行对象
		Bank bk = new Bank("中国招商银行");
		
		//银行工具类
		BankUtils bkUtils = new BankUtils();
		
		//拿到模拟数据
		DataBase db = new DataBase();
		Admin [] admins = db.getAdmin();
		Customer[] customers = db.getCostomer();
		
		//银行管理系统管理员功能封装
		BankSysMethod bkSysMethod = new BankSysMethod();
		
		//银行管理系统用户功能封装
		BankCustomerMethod bkCustomerMethod = new BankCustomerMethod();
		
		//存储登陆的管理员
		Admin admin = null;
		
		//存储登陆的用户
		Customer customer = null;
		
		//判断是否退出
		Boolean isExit = true;
		do {
			//登陆界面
			 System.out.println("Welcome to the use "+bk.getName()+"系统,请根据你的需求选择你需要的操作");
			 System.out.println("***************	请选择:	1.管理员登陆 	2.用户登陆		3.退出	***************");
			 
			 //获取输入的   int 类型的值
			 int selectMenu = bkUtils.getReadInt();
			 switch (selectMenu) {
			case 1:
				//1、管理员登陆验证,并把登陆的管理员返回
				 admin = bkSysMethod.sysRootDengLu(admins);
				 if(admin == null) {
						return;
					}
				System.out.println(admin);
				bkSysMethod.sysRootMethod(customers);
				break;
			case 2:
				customer = bkCustomerMethod.sysCustomerDengLu(customers);
				if(customer == null) {
					return;
				}
				bkCustomerMethod.bankCustomerMethod(customer);
				System.out.println("用户登陆成功");
				break;
			case 3:
				isExit = false;
				System.out.println("退出成功");
				break;
			default:
				System.out.println("你的输入有误,请重新输入!!!");
				break;
			}
			 
		} while (isExit);
	}

}

BankUtils类

package Bank;

import java.util.Scanner;

import Bank.Customer;


public class BankUtils {
	
	
	
	public String getReadString() {
			Scanner sc = new Scanner(System.in);
			String string = sc.nextLine();
		return string;
	} 
	
	
	public String getReadString(String str,String shuxing) {
			Scanner sc = new Scanner(System.in);
			String string = sc.nextLine();
			if(string.length() == 0 || string == null  ) {
				string = str;
				System.out.print("你此次未输入更改数据,该成员"+shuxing+":"+str+",属性值未变动");
				System.out.println();
			}
		return string;
	} 
	
	
	public int getReadInt() {
			Scanner sc = new Scanner(System.in);
			int num = sc.nextInt();
			return num;
	} 
	
	
	
	public int getReadNum(int nums) {
			Scanner sc = new Scanner(System.in);
			String numStr = sc.nextLine();
			if(numStr == null || numStr.length() == 0 ) {
				return nums;
			}
		return nums;
	}
	

	public double getReadDouble() {
			Scanner sc = new Scanner(System.in);
			String numStr = sc.nextLine();
			double parseDouble = (double)Integer.parseInt(numStr);
		return parseDouble;
	}
	
	
	public double getReadDouble(double doubl , String shuxing) {
			Scanner sc = new Scanner(System.in);
			String numStr = sc.nextLine();
			double parseInt;
			if(numStr == null || numStr.length() == 0 ) {
				System.out.print("你此次未输入更改数据,该成员"+shuxing+":"+doubl+",属性值未变动");
				System.out.println();
				return doubl;
			}else {
				 parseInt = (double)Integer.parseInt(numStr);
			}
		return parseInt;
	}
	
	
	
	public boolean isInt(String input) {
//		if (Integer.parseInt(input) == -1) {
//			System.out.println("已退出存钱!");
//			return false;
//		}
		for (char c : input.toCharArray()) {
			if (Character.getType(c) == Character.OTHER_LETTER) {
				System.out.println("输入错误!!!你输入的是  中文 ,请重新输入此次存钱数");
				return true;
			} else if (Character.isDigit(c)) {
				return false;
			} else if (Character.isLetter(c)) {
				System.out.println("输入错误!!!你输入的是   英文字母 ,请重新输入此次存钱数");
				return true;
			} else {
				System.out.println("输入错误!!!你的输入不符合规范,请重新输入此次存钱数");
				return true;
			}
		}
		return false;

	}
	
	
	
	public boolean verificationIsSame(Customer [] customer , String account) {
		boolean isFind = false ;
		for(int x = 0 ; x < customer.length ; x++) {
				if(customer[x].getAccount().equals(account)) {
					System.out.println("该账号已存在,请重新输入!!!");
					isFind = true;
					return isFind;
				}
		}
			return isFind;
	}
	
	
	
	public Customer[] addCapacity(Customer [] customer) {
		
		Customer []  newCustomer = new Customer[customer.length + 1] ;
		
		//判断传进来的数组长度是否大于等于10
		if(customer.length >= 10) {
			//如果数组长度大于等于10,把object数组的值赋值给newObj
			for(int x = 0 ; x < customer.length ; x++) {
				newCustomer[x] = customer[x];
			}
			
		}
		
		return newCustomer;
	}
	
}

Customer类

package Bank;

import java.util.Scanner;

import Bank.BankUtils;
import Bank.Customer;


public class Customer {
	
	//客户属性
	private String name;//用户
	private String account;	//用户账号
	private String password;//用户密码
	private	double balance; //用户余额
	private String phone; //用户手机号
	
	
	//toString方法
	public String toString() {
		return "Customer [name=" + name + ", account=" + account + ", password=" + password + ", balance="
				+ balance + ", phone=" + phone + "]";
	}
	
	//客户无参构造方法
	public Customer() {
		super();
	}
	
	//客户有参构造方法
	public Customer(String name, String account, String password, double balance, String phone) {
		super();
		this.name = name;
		this.account = account;
		this.password = password;
		this.balance = balance;
		this.phone = phone;
	}
	
	
	//属性get/set方法
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getAccount() {
		return account;
	}
	public void setAccount(String account) {
		this.account = account;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public double getBalance() {
		return balance;
	}
	public void setBalance(double balance) {
		this.balance = balance;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	
	
	
	/**
	 * 此方法将打印所有的用户信息数据
	 * 	 	如果没有用户信息,则显示 无用户信息可查询。
	 */
	public void printAllCustomer(Customer[] customer) {
		
		if(customer.length == 0) {
			System.out.println("没有可查询的用户信息!");
			return;
		}
		System.out.println("序号 \t用户名 \t\t\t用户账号 \t\t用户密码 \t\t用户余额 \t\t用户手机号");
		for(int x = 0 ; x < customer.length ; x++) {
			 String name = customer[x].getName();//用户
			 String account = customer[x].getAccount();//用户账号
			 String password = customer[x].getPassword();//用户密码
			 double balance = customer[x].getBalance(); //用户余额
			 String phone = customer[x].getPhone(); //用户手机号
			
			 System.out.println((x+1)+ "\t" + name + "\t\t" + account + "\t\t" + password + "\t\t" + balance + "\t\t" + phone );
			
		}
	}
	
	
	BankUtils bkUtils = new BankUtils();
	/*
	 *管理员对用户的信息修改功能
	 */
	public void updateUser(Customer[] customer) {
		//获得需要修改的用户账号
		System.out.println("请输入你需要修改的用户账号:");
		String updateAccount = bkUtils.getReadString();
		
		 //如果有该账号,记录该账号的下标。
		 int index = -1;
		for(int x = 0 ; x < customer.length ; x++) {
			if(customer[x].getAccount().equals(updateAccount)) {
				index = x;
			}
		}
		
		//根据用户序号修改用户信息
		if(index != -1) {
			 String name = customer[index].getName();//用户
			 String password = customer[index].getPassword();//用户密码
			 double balance = customer[index].getBalance(); //用户余额
			 String phone = customer[index].getPhone(); //用户手机号
			 
			 System.out.println("----------------------------------------------");
			 System.out.println("如无需改动用户的属性,直接回车即可");
			 System.out.println("----------------------------------------------");
			 System.out.println();
					 
			 System.out.println("请输入新用户名("+name+"):");
			 String newName = bkUtils.getReadString(name,"用户名");
			 System.out.println("请输入用户新密码("+password+"):");
			 String newPassword = bkUtils.getReadString(password,"用户密码");
			 System.out.println("请输入用户余额("+balance+"):");
			 double newBalance = bkUtils.getReadDouble(balance,"用户余额");
			 System.out.println("请输入用户手机号("+phone+"):");
			 String newPhone = bkUtils.getReadString(phone,"用户手机号");
			 
			 customer[index].setName(newName);
			 customer[index].setPassword(newPassword);
			 customer[index].setBalance(newBalance);
			 customer[index].setPhone(newPhone);
			 System.out.println("修改成功");
		}else {
			System.out.println("修改失败,你输入的用户序号不存在!!!");
		}
	}
	
	
	//存储扩容后的数组
	Customer [] newCustomers ;
	
	public Customer[] addCustomer(Customer [] customers) {
		/*
		 * 需要添加的对象数据
		 *  private String name;//用户
		 *	private String password;//用户密码
		 *	private	double balance; //用户余额
		 *	private String phone; //用户手机号
		 * 
		 */
		System.out.println("---------------添加开始---------------");
			System.out.println("请输入添加的客户用户名:");
			String name = bkUtils.getReadString();
			
			//判断输入的用户账号是否相同;
			String account = null ;
			boolean isFlag = true;
			while(isFlag) {
				System.out.println("请输入添加的客户账号:");
				 account = bkUtils.getReadString();
				
				boolean verificationIsSame = bkUtils.verificationIsSame(customers, account);
				isFlag = verificationIsSame;
			}
			
			System.out.println("请输入添加的客户密码:");
			String password = bkUtils.getReadString();
			
			System.out.println("请输入添加的客户余额:");
			double blance = bkUtils.getReadDouble();
			
			System.out.println("请输入添加的客户手机号:");
			String phone = bkUtils.getReadString();
			
			Customer newCustomer = new Customer(name , account , password , blance , phone);
			
			/**
			 * 往对象里面添加新数据,要判断数据的长度,如果数组长度大于等于10,则每次添加数据需要对数组进行动态扩容。
			 * 
			 */
				//数组扩容
				newCustomers = bkUtils.addCapacity(customers);
				newCustomers[customers.length] = newCustomer;
				
				
			System.out.println("---------------添加完成---------------");
			
			return newCustomers;
	}
	
	
	/**
	 * 根据序号删除客户信息
	 * @param customer
	 * @return
	 */
	
	public Customer[] deleteCustomer(Customer [] customer) {
		
		/*
		 * 
		 * 用户删除:
		 * 		1.获得输入需要删除的序号
		 * 		2.判断输入的序号是否存在
		 * 			(1)获得指定序号得用户账号;
		 * 			(2)遍历循环数组,查看数组中是否存在 获得得指定用户账号。如果存在,记录下该数组下标
		 * 		3.如果序号存在,则根据序号删除用户; 如果序号不存在,则提示删除失败,并返回管理员界面;
		 * 			(1)删除数组中得指定用户,其实就是把该位置下标的数据用后一位下标的数组下标替换;
		 * 			(2)重新创建一个新的数组接收减容后的数组
		 * 		4.返回一个删除指定序号用户的数组Customer [] 
		 */
		
		//1.获得输入需要删除的序号
		System.out.println("请输入你需要删除的客户序号:");
		int deleteInt = bkUtils.getReadInt();
		
		//2.判断输入的序号是否存在
			//(1)获得指定序号得用户账号;
			String deleteAccount = customer[deleteInt - 1].getAccount();
		//	(2)遍历循环数组,查看数组中是否存在 获得得指定用户账号。
				//记录该数组下标;
				int index = -1;
		for(int x = 0 ; x < customer.length ; x++) {
			//因为不能直接获得序号,所以可以根据序号获得该序号得顺序,并判断该数组里面是否存在该账号;
			//	如果不存在,则说明已删除过,删除失败。
			if(customer[x].getAccount().equals(deleteAccount)) {
				index = x;
			}
		}
		
		//做一下判断,如果要删除的账号还有余额,则不能删除。
		 if(customer[index].getBalance() != 0) {
			System.out.println("---------------该账号用户余额不为0,删除失败!!!---------------");
			System.out.println();
			return customer;
		} 
		/*
		 *3.如果序号存在,则根据序号删除用户; 如果序号不存在,则提示删除失败,并返回管理员界面;
		 * 			(1)删除数组中得指定用户,其实就是把该位置下标的数据用后一位下标的数组下标替换;
		 * 			(2)数组减容。 
		 */
		
		//定义数组接收减容后的数据
		Customer [] deleteCustomer = new Customer[customer.length - 1];
		
		if(index != -1) {
			for(int d = index ; d < customer.length - 1; d++) {//数组最后一位数据无需替换
				//替换数组数据
				customer[d] = customer[d+1];
			}
			//数组减容
			for(int e = 0; e < customer.length - 1 ; e++) {
				deleteCustomer[e] = customer[e];
			}
			System.out.println("---------------删除成功---------------");
		}else {
			System.out.println("---------------未找到该序号用户,删除失败!!!---------------");
			System.out.println();
			return customer;
		}
		return deleteCustomer;
	}
	
	
	
	/**
	 * 本方法用于对用户存钱的功能实现;
	 * 
	 * @param customer
	 * 
	 */
	public void addMoney(Customer dengLuCustomer) {
		/*
		 * 获得用户存钱数量,根据用户修改用户的余额。
		 * 		1.获得用户存钱数量。
		 * 		2.对用户存钱数量进行校验
		 * 			(1)不能为负数
		 * 			(2)类型只能为数字。
		 * 		3.校验完成之后,修改该用户余额数
		 * 		4.返回数据。
		 * 		
		 */
		
		/*
		 * 		1.获得用户存钱数量。
		 * 		2.对用户存钱数量进行校验
		 * 			(1)不能为负数
		 * 			(2)类型只能为数字。
		 */
		boolean isInt = true ;
		String input = null ; 
		int addMoneyNum = 0;
		while(isInt) {
			System.out.println("请输入你本次存钱数量:");
			
			@SuppressWarnings("resource")
			Scanner scanner = new Scanner(System.in);
			 input = scanner.next();
			 isInt = bkUtils.isInt(input);
			 
			
		}
		 
		
		 //3.校验完成之后,修改该用户余额数
		if(!isInt) {
			 addMoneyNum = Integer.parseInt(input);
			double momey =dengLuCustomer.getBalance();
			dengLuCustomer.setBalance(addMoneyNum + momey);
			System.out.println("---------------存钱成功---------------");
			System.out.println();
			System.out.println("您当前余额为"+dengLuCustomer.getBalance());
			
		}else {
			System.out.println("---------------存钱失败---------------");
		}
		
		
	}
	
	
	
	
	/**
	 * 本方法用于对用户取钱的功能实现;
	 * @param dengLuCustomer
	 */
	public void deleteMoney( Customer dengLuCustomer) {
		/*
		 * 获得用户取钱数量,根据用户修改用户的余额。
		 * 		1.获得用户存钱数量。
		 * 		2.对用户存钱数量进行校验
		 * 			(1)不能为负数
		 * 			(2)取钱数不能大于存钱数。
		 * 		3.校验完成之后,修改该用户余额数
		 * 		4.返回数据。
		 * 		
		 */
		
		boolean isInt = true ;
		String input = null ; 
		int deleteMoneyNum = 0;
		while(isInt) {
			System.out.println("请输入你本次取钱数量:");
			
			@SuppressWarnings("resource")
			Scanner scanner = new Scanner(System.in);
			 input = scanner.next();
			 isInt = bkUtils.isInt(input);
		}
		
		 //3.校验完成之后,修改该用户余额数
		if(!isInt ) {
			
			if(Integer.parseInt(input) > dengLuCustomer.getBalance()) {
				 isInt = true;
				 System.out.println("账户余额不足!本次取款数大于余额,请重新输入!!!");
				 System.out.println();
			 }
			
			 deleteMoneyNum = Integer.parseInt(input);
			double momey =dengLuCustomer.getBalance();
			dengLuCustomer.setBalance(momey - deleteMoneyNum);
			System.out.println("---------------取钱成功---------------");
			System.out.println();
			System.out.println("您当前余额为"+dengLuCustomer.getBalance());
			
		}else {
			System.out.println("---------------取钱失败---------------");
		}
		
	}
	
	
	
	/**
	 * 修改用户密码
	 * @param dengLuCustomer
	 */
	public void updaterCustomerPsd(Customer dengLuCustomer) {
		/*
		 * 	1.修改密码前先输入自身密码才可进行修改;
		 * 	2.获取用户两次输入的密码;
		 *  3.判断两次输入的密码是否一致;
		 *  	如果两次输入的密码不一致,重新输入;
		 *  	若两次输入的密码一致,提示修改成功;
		 * 
		 */
		boolean isSuccess = true;
		String psd = null;
		String userPsd = null;
		while(isSuccess) {
			
			//1.修改密码前先输入自身密码才可进行修改;
			System.out.println("请输入你的密码:");
			psd = bkUtils.getReadString();
			userPsd = dengLuCustomer.getPassword();
			
		if(psd.equals(userPsd)) {
				//2.获取用户两次输入的密码;
				boolean isflag = true;
				String psd1 = null;
				String psd2 = null;
				while(isflag) {
					
						System.out.println("请输入你需要修改的密码:");
						psd1 = bkUtils.getReadString();
						//判断输入的密码是否为空
						if(psd1.length() == 0 || psd1 == null) {
							System.out.println("输入的密码不能为空!!!");
							break;
						}
						
						System.out.println("请再一次输入你需要修改的密码:");
						psd2 = bkUtils.getReadString();
						//判断输入的密码是否为空
						if(psd2.length() == 0 || psd2 == null) {
							System.out.println("输入的密码不能为空!!!");
							break;
						}
						/*
						 * 3.判断两次输入的密码是否一致;
						 *  	如果两次输入的密码不一致,重新输入;
						 *  	若两次输入的密码一致,提示修改成功;
						 */
						if(psd1.equals(psd2)) {
							userPsd = psd2;
							dengLuCustomer.setPassword(psd2);
							isflag = false;
							isSuccess = false;
							System.out.println("---------------密码修改成功,你的新密码是:"+dengLuCustomer.getPassword()+",请牢记---------------");
							return;
						}else {
							System.out.println("---------------密码修改失败---------------");
						}
					}
			}else {
				System.out.println("你输入的密码错误,请重新输入!!!");
			}	
		}
		
	}
	
	
	public void displayCustomer(Customer customer) {
		
		System.out.println("用户名\t\t\t用户账号\t用户密码\t用户余额\t用户手机号");
		 String name = customer.getName();//用户
		 String account = customer.getAccount();//用户账号
		 String password = customer.getPassword();//用户密码
		 double balance = customer.getBalance(); //用户余额
		 String phone = customer.getPhone(); //用户手机号
		System.out.println(name + "\t\t" + account + "\t\t" + password + "\t\t" + balance + "\t\t" + phone );
		System.out.println();
	}
}

DateBase类

package Bank;

import Bank.Admin;
import Bank.Customer;

public class DataBase {
	
			//定义一个数组存储管理员信息
			private	Admin [] admins  = new Admin[3];
			//定义一个数组存储用户信息
			private	Customer [] customers  = new Customer[10];
			
			//定义获取管理Admin信息的get/set方法
			public Admin[] getAdmins() {
				return admins;
			}
			public void setAdmins(Admin[] admins) {
				this.admins = admins;
			}
			
			//定义获取用户Customer信息的get/set方法
			public Customer[] getCustomers() {
				return customers;
			}
			public void setCustomers(Customer[] customers) {
				this.customers = customers;
			}
			
			
			//模拟存储的管理员信息
			public Admin[] getAdmin() {
				
					for(int x = 1 ; x <= admins.length ; x++) {
						admins[x - 1]= new Admin("admin0"+x,"abc"+x);
					}
					return admins;
			}
			
			
			//模拟存储的用户信息
			public Customer[] getCostomer() {
				
				for(int x = 1 ; x <= customers.length ; x++) {
					customers[x - 1]= new Customer("customerName0"+x,"user0"+x,"abcde"+x,10000,"11122233"+x);
				}
				return customers;
			}
			
}

 

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值