最初の小規模プロジェクトATM

序文:オブジェクト指向で書かれた最初の小さなプロジェクトであるATMを完成させました。この記事のコードはすべて、オブジェクト指向の記述に基づいています。

プロジェクト要件:

  1. 登録:ユーザー名、携帯電話番号、ID番号、カード番号、パスワード。
  2. クエリ:アカウントが存在する必要があり、パスワードが必要です(3つの可能性、カードが間違っている場合はロックします)。
  3. 引き出し:アカウントが存在する必要があり、パスワード(3回のチャンス、カードが間違っている場合はカードをロックします)、および引き出し金額はデポジットを超えることはできません。
  4. デポジット:アカウントが存在している必要があり、デポジット金額は0未満にはできません。
  5. 送金:アカウントと送金アカウントの両方が存在する必要があり、パスワード(3回のチャンス、カードが間違っている場合はカードをロックします)、および送金金額が残高を超えることはできません。
  6. カードロック:アカウントが存在する必要があります。パスワードで凍結するか、ID番号で凍結することができます。
  7. カードのロック解除:アカウントが存在している必要があり、ID番号のみを使用してロックを解除できます。
  8. カードの更新:IDカードを確認してカードを更新します。更新後、以前のカードは無効になります。
  9. パスワードの変更:パスワードを変更したい、またはIDカードを使用してパスワードを変更したい。
  10. 終了:データを保存

完成した外観:

入力後、まずユーザー登録を行い、ユーザー名、IDカード、携帯電話番号、パスワードを1回入力し、1回確認します。登録が完了したら、ユーザー操作インターフェイスに入ります。インターフェイスには、サブジェクトが必要とする機能があり、ユーザーは自分のニーズに応じて操作して、ユーザーのニーズを達成できます。

登録インターフェース

void logon() {
    
    
//储存的身份证、用户名、手机号都存储在一个叫Card的类里面,体现面向对象
的思想。
		System.out.println("欢迎进入注册系统!");
		Scanner input = new Scanner(System.in);
		System.out.println("请输入你的账户:");
		super.setAccount(input.next());
		System.out.println("请输入你的手机号:");
		super.setPhone(input.nextInt());
		System.out.println("请输入你的身份证号:");
		super.setIdcard(input.nextInt());
		while (true) {
    
    
			System.out.println("请输入你的密码:");
			int passWord1 = input.nextInt();
			System.out.println("请再输入一次你的密码:");
			int passWord2 = input.nextInt();
			//判断两次的输入是否一致
			if(passWord1 == passWord2 ){
    
    
				super.setPassWord(passWord1);
				System.out.println(super.getPassWord());
				break;
			}
			System.out.println("两次输入的密码不相同,请重新开始!");
		}
		Random random = new Random();
		//随机生成卡号
		//因为要的是一个16位数的卡号,我分成了2个8位数的long类型的数
		long a;
		long b;
		while(true) {
    
    
			a = random.nextInt(99999999);
			if(a>10000000) {
    
    //判断一下随机生成的数,是否是一个8位数的
				while(true) {
    
    
					b = random.nextInt(99999999);
					if(b>10000000) {
    
    
					//让a*100000000+b,组成一个16位的数。
						super.setCardid(a*100000000+b);
						break;
					}
				}
			}
			break;
		}
		System.out.println("你的卡号是:"+super.getCardid());
	}

ログインインターフェース

ログインインターフェイスでは、ユーザーが入力したアカウントとパスワードを、保存されているアカウントとパスワードと照合します。

void regiser() {
    
    
		Scanner input = new Scanner(System.in);
		System.out.println("欢迎进入登录界面");
		//在登陆时判断卡是否被锁,用super()来调用父类的数据
		if (super.isIslock()==false) {
    
    
			System.out.println("你的卡已被锁,请解锁");
		}
		while(true) {
    
    
			int count = 0;
			System.out.println("请输入你的卡号:");
			long cardid2 = input.nextLong();
			if (cardid2==super.getCardid()) {
    
    
				System.out.println("请输入你的密码:");
				int passWord2 = input.nextInt();
				System.out.println(super.getPassWord());
				if (super.getPassWord()==passWord2) {
    
    
					System.out.println("登录成功");
					break;
				}else {
    
    
					System.out.println("密码错误,请重新输入");
					count++;
					if(count==3) {
    
    
						super.setIslock(false);
					}
				}
			}else {
    
    
				System.out.println("账号错误,请重新输入");
				count++;
				//用变量count来计数,当为3的时候锁卡下次登陆就要先去解卡
				if(count==3) {
    
    
					super.setIslock(false);
				}
			}
		}
	}

入金インターフェース

お金を数える本物のATMはないので、ここでの預金はユーザーが自分で入力し、金持ちの中毒を持っているためです(ただし、しばらくの間だけです)

void addMoney() {
    
    
		Scanner ipnut = new Scanner(System.in);
		System.out.println("欢迎进入存款界面");
		Scanner input = new Scanner(System.in);
		System.out.println("请先登录");
		this.regiser();
		if (super.isIslock()==false) {
    
    
			System.out.println("你的卡已被锁");
		}else {
    
    
			System.out.println("请输入你的存款的金额:");
			int add = input.nextInt();
			super.setMoney (super.getMoney() + add);
			System.out.println("你的账户有" + super.getMoney());
		}
	}

引き出しインターフェイス

void gainMoney() {
    
    //取款
		System.out.println("欢迎进入取款界面");
		Scanner input = new Scanner(System.in);
		System.out.println("请先登录");
		this.regiser();
		if (super.isIslock()==false) {
    
    
			System.out.println("你的卡已被锁,请解锁");
		}else {
    
    
			System.out.println("请输入你的取款的金额:");
			int gain = input.nextInt();
			//判断取款的金额是否大于存款数
			if (gain>super.getMoney()) {
    
    
				System.out.println("账户余额不足");
			}else {
    
    
				super.setMoney (super.getMoney()-gain);
				System.out.println("你的账户有"+super.getMoney());
			}
		}
	}

クエリインターフェイス

void query() {
    
    
		System.out.println("欢迎进入查询界面");
		System.out.println("请先登录");
		this.regiser();
		if (super.isIslock()==false) {
    
    
		//判断是否锁卡
			System.out.println("你的卡已被锁,请解锁");
		}else {
    
    
			System.out.println("卡内余额:" + super.getMoney());
		}
	}

ロックカードインターフェイス

void lock() {
    
    
		System.out.println("欢迎进入锁卡界面");
		Scanner input = new Scanner(System.in);
		System.out.println("请先登录");
		this.regiser();
		if (super.isIslock()==false) {
    
    
			System.out.println("你的卡已被锁");
		}else {
    
    
			System.out.println("是否要执行锁卡操作  1.是  2.否");
			int choice3 = input.nextInt();
			if (choice3==1) {
    
    
				super.setIslock(false);
				System.out.println("锁卡成功");
			}else {
    
    
				super.setIslock(true);
				System.out.println("锁卡失败");
			}
		}
	}

インターフェースのロックを解除

void unlock() {
    
    
		Scanner input = new Scanner(System.in);
		System.out.println("欢迎进入解锁界面");
		while(true) {
    
    
			System.out.println("请输入你解锁卡的身份证号");
			int idcard2 = input.nextInt();
			if(idcard2 == super.getIdcard()) {
    
    
				System.out.println("验证成功");
				System.out.println("你的卡已解锁");
				super.setIslock(true);
				break;
			}else {
    
    
				System.out.println("验证失败,请重新输入");
			}
		}
	}

カード交換インターフェース

void newCard() {
    
    
		System.out.println("欢迎进入补卡界面");
		Scanner input = new Scanner(System.in);
		Random random = new Random();
		while (true) {
    
    
		//调用数据对比身份证信息
			System.out.println("请输入你的身份证进行验证:");
			int idcard1 = input.nextInt();
			if (super.getIdcard() != idcard1) {
    
    
				System.out.println("请重新输入你的身份证进行验证:");
				idcard1 = input.nextInt();
			}
			break;
		}
		while(true) {
    
    
		//生成一个新的卡号
			int a = random.nextInt(99999999);
			int b = random.nextInt(99999999);
			if(a>10000000 && b>10000000) {
    
    
				super.setCardid(a*10000000+b);
				break;
			}
		System.out.println("请重新输入你的身份证进行验证:" + super.getCardid());
		}
	}

パスワードインターフェイスの変更

void changePwd() {
    
    
		System.out.println("欢迎进入修改密码界面");
		Scanner input = new Scanner(System.in);
		while (true) {
    
    
			System.out.println("请输入你的身份证进行验证:");
			int idcard1 = input.nextInt();
			if (super.getIdcard() != idcard1) {
    
    
				System.out.println("请重新输入你的身份证进行验证:");
				idcard1 = input.nextInt();
			}
			break;
		}
		System.out.println("请输入你的新密码");
		super.setPassWord(input.nextInt());
		System.out.println("修改密码成功");
	}

データを格納するための親クラス

public class Card {
    
    //把数据都存放到这个里面
	static int money;
	static boolean islock = true;
	static int idcard;
	static int phone ;
	static String account;
	static long cardid;
	static int passWord;
	
	public Card(int money, boolean islock, int idcard, int phone, String account, long cardid, int passWord) {
    
    
		super();
		this.money = money;
		this.islock = islock;
		this.idcard = idcard;
		this.phone = phone;
		this.account = account;
		this.cardid = cardid;
		this.passWord = passWord;
	}
	public Card() {
    
    
		super();
	}
	public int getMoney() {
    
    
		return money;
	}
	public void setMoney(int money) {
    
    
		this.money = money;
	}
	public boolean isIslock() {
    
    
		return islock;
	}
	public void setIslock(boolean islock) {
    
    
		this.islock = islock;
	}
	public int getIdcard() {
    
    
		return idcard;
	}
	public void setIdcard(int idcard) {
    
    
		this.idcard = idcard;
	}
	public int getPhone() {
    
    
		return phone;
	}
	public void setPhone(int phone) {
    
    
		this.phone = phone;
	}
	public String getAccount() {
    
    
		return account;
	}
	public void setAccount(String account) {
    
    
		this.account = account;
	}
	public long getCardid() {
    
    
		return cardid;
	}
	public void setCardid(long cardid) {
    
    
		this.cardid = cardid;
	}
	public int getPassWord() {
    
    
		return passWord;
	}
	public void setPassWord(int passWord) {
    
    
		this.passWord = passWord;
	}
}

おすすめ

転載: blog.csdn.net/weixin_46687295/article/details/106006609