Java--网上银行登录及存取款业务模拟系统

package hello;

import java.util.HashMap;
import java.util.Scanner;

public class Bank {
	int frequency = 3;
	Scanner in = new Scanner(System.in);
	HashMap<String, User> u1 = Test.users;;
	User u;
	public void Land() {
		while (true) {
			System.out.print("请输入银行卡卡号:");
			String Cardnumber = in.nextLine();
			System.out.print("请输入银行卡密码:");
			String Password = in.nextLine();
			u = u1.get(Cardnumber);
			if (u1.containsKey(Cardnumber) && u.getPassword().equals(Password)) {
				System.out.println("恭喜您登陆成功!");
				System.out.println("欢迎" + u.getName() + "先生");
				operation();// 操作
				break;
			} else {
				if (frequency <= 3 && frequency > 0) {
					frequency--;
					System.out.println("账号或密码或者是姓名输入错误请重新输入!  您还有" + frequency + "次机会输入");
					System.out.println("**********************");
				}
				if (frequency == 0) {
					System.out.println("您输入错误以达3次,已强制退出,请稍后重试!");
					System.out.println("**********************");
					System.exit(0);
				}
			}

		}
	}

	public void operation() {// 操作
		while (true) {
			System.out.println("**********************");
			System.out.println("请输入您要进行的操作:");
			System.out.println("0.退出 ");
			System.out.println("1.存款	");
			System.out.println("2.取款 	");
			System.out.println("3.余额	");
			System.out.println("**********************");
			int reader=0;
            try {
            	 reader = Integer.parseInt(in.nextLine().trim());
            }catch(Exception e){
            	System.out.println("你输入的数据类型不对,请重新输入");
            	continue;
            }
			switch (reader) {
			case 1:
				System.out.println("*******************");
				System.out.println("请输入存款金额:");
				try {
					int Depositmoney = Integer.parseInt(in.nextLine().trim());
					deposit(Depositmoney);
					break;
	            }catch(Exception e){
	            	System.out.println("你输入的数据类型不对,已退出存款");
	            	continue;
	            }
			case 2:
				System.out.println("*******************");
				System.out.println("请输入取款金额:");
				try {
					int  Withdrawmoney = Integer.parseInt(in.nextLine().trim());
					Withdraw(Withdrawmoney);
					break;
	            }catch(Exception e){
	            	System.out.println("你输入的数据类型不对,已退出取款");
	            	continue;
	            }
			case 3:
				balance();
				break;
			case 0:
				System.out.println("*******************");
				System.out.println("请您携带好您的随身物品,再见!");
				System.out.println("*******************");
				return;
				default:
					System.out.println("请输入正确的数字");
					break;
			}
		}
	}

	public void deposit(int amount) {// 存钱
		int account = u.getDeposit() + amount;
		u.setDeposit(account);
		System.out.println("存款成功,您成功存入了" + amount);
		System.out.println("客户您好,您的目前的余额为" + u.getDeposit());
	}

	public void Withdraw(int amount) {// 取钱
		if (amount > u.getDeposit()) {
			System.out.println("对不起,您要取的金额超出范围!");
			System.out.println("您目前剩余的金额为" + u.getDeposit());

		} else {
			int balance;
			balance = u.getDeposit() - amount;
			u.setDeposit(balance);
			System.out.println("恭喜您,取款成功,您成功取出" + amount + "元");
			System.out.println("客户您好,您的目前的余额为" + u.getDeposit());
		}
	}

	public void balance() {// 显示余额
		System.out.println("客户您好,您的余额为" + u.getDeposit());
	}
}

package hello;

import java.util.HashMap;

public class Test {
	 public static HashMap<String, User> users = new HashMap<String, User>();
	public static void main (String [] agrs) {
		//熊大
		User u1 = new User();
		u1.setName("熊大");
		u1.setCall("111");
		u1.setCardnumber("123321");
		u1.setDeposit(0);
		u1.setPassword("123321");
		users.put(u1.getCardnumber(),u1);
		//熊
		User u2 = new User();
		u2.setName("熊二");
		u2.setCall("222");
		u2.setCardnumber("456654");
		u2.setDeposit(0);
		u2.setPassword("456654");
		users.put(u2.getCardnumber(),u2);
		//翠花
		User u3 = new User();
		u3.setName("翠花");
		u3.setCall("333");
		u3.setCardnumber("789987");
		u3.setDeposit(0);
		u3.setPassword("789987");
		users.put(u3.getCardnumber(),u3);
		Bank bank = new Bank();
		bank.Land();
	}
}

package hello;

public class User {
    private String name;//名字
    private String Cardnumber;//银行卡号
    private String Password;//银行卡密码
    private String call;//电话号码
    private int deposit;//存款
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getCardnumber() {
		return Cardnumber;
	}
	public void setCardnumber(String cardnumber) {
		Cardnumber = cardnumber;
	}
	public String getPassword() {
		return Password;
	}
	public void setPassword(String password) {
		Password = password;
	}
	public String getCall() {
		return call;
	}
	public void setCall(String call) {
		this.call = call;
	}
	public int getDeposit() {
		return deposit;
	}
	public void setDeposit(int deposit) {
		this.deposit = deposit;
	}
    
}

你可能感兴趣的:(Java)