今日学习ATM项目
package com.fzyun;
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
public class ATMSystem {
public static void main(String[] args) {
//1.定义一个账户类
//2.定义一个集合容器,负责以后存储全部的账户对象,进行相关的业务操作
ArrayList<Account> accounts = new ArrayList<>();
Scanner sc = new Scanner(System.in);//放在外面节省内存。
//3.展示系统的首页
while (true) {
System.out.println("==========ATM系统==========");
System.out.println("1:账户登录");
System.out.println("2:用户注册");
System.out.println("请您选择数字进行操作");
int command = sc.nextInt();
switch (command){
case 1:
//用户登录
break;
case 2:
//用户注册——创建方法,Alt+回车+回车
register(accounts,sc);
break;
default:
System.out.println("您输入的操作命令不存在");
}
}
}
/**
* 方法目的:用户注册开户
* private只能在本类中使用
* @param accounts 接受账户的集合
*/
private static void register(ArrayList<Account> accounts,Scanner sc) {
System.out.println("=======系统注册界面========");
//1.创建一个账户对象,用于后期封装账户信息
Account account = new Account();
//2.录入账户信息,注入到账户对象中去
System.out.println("请您输入账户名称:");
String userName = sc.next();
account.setUserName(userName);//将信息收录进账户中去
while (true) {
System.out.println("请您输入账户名称:");
String passWord = sc.next();
System.out.println("请您再次确认密码:");
String okPassWord = sc.next();
if (okPassWord.equals(passWord)){
//认证通过,可以注册
account.setPassWord(okPassWord);
break;//密码录入成功
}else {
System.out.println("您输入的两次密码不一致,请重新确认");
}
}
System.out.println("请您输入账户当次限额:");
double quotaMoney = sc.nextDouble();
account.setQuotaMoney(quotaMoney);
//为账户生成随机八位且与其他账号不重复的号码
String carID = getRandomCardID(account);
//3. 将账户对象添加到账户集合中
}
/**
* 为我们账户生成八位与其他账户卡号不同的号码
* @return
*/
private static String getRandomCardID(ArrayList<Account> accounts) {
//1.先生成8位数字
String cardID = "";
Random r = new Random();
for (int i = 0; i < 8; i++) {//随机八个数字,将其连接起来
cardID += r.nextInt(10);//bound 10,生成数字范围为0-9 10位数
}
//2.判断8位卡号是否重复
return null;//return cardID;错误,不能直接返回,有可能与其他人的ID重复
}
/**
* 根据卡号查询出一个账户对象
* @param cardID
* @param accound
* @return
*/
private static Account getAccountByCardID(String cardID , ArrayList<Account> accound){
}
}
package com.fzyun;
/**
账户类
*/
public class Account {
private String cardID;
private String userName;
private String passWord;
private Double money;//账户余额
private Double quotaMoney;//每次取现额度
//无参数构造器是默认提供的
public String getCardID() {
return cardID;
}
public void setCardID(String cardID) {
this.cardID = cardID;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassWord() {
return passWord;
}
public void setPassWord(String passWord) {
this.passWord = passWord;
}
public Double getMoney() {
return money;
}
public void setMoney(Double money) {
this.money = money;
}
public Double getQuotaMoney() {
return quotaMoney;
}
public void setQuotaMoney(Double quotaMoney) {
this.quotaMoney = quotaMoney;
}
}
标签:总结,4.14,账户,System,println,out,public,String
From: https://www.cnblogs.com/XiMenXve/p/17319968.html