本银行ATM系统还不够完善,只适合初学者,其中没有添加修改用户信息的功能,还有多用户功能。其中修改用户信息可以通过get(),set()方法,加上判断即可,而多用户功能可以使用多个数组加上判断即可解决。希望能帮助到你。
package 面向对象;
//功能部分
import java.util.Scanner;
public class Account {
private String id,password,personid,name,email;
private double balance;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getPersonid() {
return personid;
}
public void setPersonid(String personid) {
this.personid = personid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
//登陆
public boolean login(){
boolean flg=false;
flg=zhanghaojiancha();
if(flg){
flg=mimajiancha();
if(flg){
System.out.println("登陆成功,请继续");
}
else{
System.out.println("密码输入超过5次!您的卡已被冻结");
}
}
else{System.out.println("账号输入超过5次!您的卡已被冻结");
}
return flg;
}
//存款
public void deposit(){
boolean flg=true;
if(flg){
System.out.print("请输入存款金额:");
Scanner input=new Scanner(System.in);
double inMoney=input.nextInt();
if(inMoney>0.0&&(inMoney%100==0)){
this.balance=this.balance+inMoney;
System.out.println("存款成功");
System.out.println("存款:"+inMoney);
System.out.println("余额:"+balance);
}else System.out.print("您输入的存款金额有误,请重新输入:");
}
}
//取款
public void withdraw(){
boolean flg=true;
if(flg){
System.out.print("请输入取款金额:");
Scanner input=new Scanner(System.in);
double outMoney=input.nextInt();
if(outMoney>=100&&(outMoney%100==0)){
this.balance=this.balance-outMoney;
System.out.println("取款成功");
System.out.println("取款:"+outMoney);
System.out.println("余额:"+balance);
}
else System.out.print("您输入的取款金额有误,请重新输入:");
}
}
//账号检查
public boolean zhanghaojiancha(){
System.out.println("请输入账号:");
Scanner input=new Scanner(System.in);
String id=input.next();
boolean flg=false;
for(int i=1;i<5;i++){
if(!(this.id.equals(id))){
System.out.println("您还有"+(5-i)+"次机会");
System.out.println("请重新输入账号:");
Scanner input1=new Scanner(System.in);
id=input1.next();
}
else {System.out.println("请继续");
flg=true;
break;
}
}
return flg;
}
//密码检查
public boolean mimajiancha(){
boolean flg=false;
System.out.println("请输入密码:");
Scanner input=new Scanner(System.in);
String password=input.next();
for(int i=1;i<5;i++){
if(!(this.password.equals(password))){
System.out.println("您还有"+(5-i)+"次机会");
System.out.println("请重新输入密码:");
Scanner input1=new Scanner(System.in);
password=input1.next();
}
else {
flg=true;
break;
}
}
return flg;
}
}
//main函数用户执行区
package 面向对象;
import java.util.Scanner;
public class Account1 extends Account {
public static void main(String[] args) {
// TODO Auto-generated method stub
boolean flg=false;
Account s=new Account1();
s.setId("123456");
s.setPassword("123456");
s.setPersonid("610222199405170111");
s.setEmail("[email protected]");
s.setName("柴小贱");
s.setBalance(2.0);
flg=s.login();
if(flg){
System.out.println("请输入您要执行的操作(0:存款/1:取款)");
Scanner input=new Scanner(System.in);
int i =input.nextInt();
if(i==0){
s.deposit();
}else{
s.withdraw();
}
}
System.out.println("欢迎下次光临");
}
}