java简单的增删改查项目
login:
package atm;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
* 方法
* @author 王炳祥
*
*/
public class login {
//实例化注册人员类的一个对象
zcUser Z = new zcUser();
// zcUser泛型 全局变量
public List<zcUser> zcr1 = new ArrayList();
/**
* 注册
*
*/
public void zc() {
boolean a = true;
System.out.print("请输入注册账号:");
Scanner sc = new Scanner(System.in);
int account = sc.nextInt();
while (a) {
System.out.print("请设定您的密码:");
int pwd1 = sc.nextInt();
System.out.print("请确定您的密码:");
int pwd2 = sc.nextInt();
if (pwd1 == pwd2) {
// 初始化调用有参构造器
zcUser zc = new zcUser(account, pwd1);
// 将值添加到zcr
zcr1.add(zc);
//利用get方法将值取出 此时temp是地址
zcUser temp = zcr1.get(0);
// System.out.println(temp.account);
System.out.println("注册成功");
System.out.println("是否进行登录\n1: 登录\n2:返回主界面");
System.out.println("请选择将要进行的操作:");
int sf = sc.nextInt();
if(sf==1) {
dl();
}else {
if(sf==2) {
xz();
}else {
System.out.println("您选择的操作不存在,即将返回主界面");
xz();
}
}
a = false;
} else {
System.out.println("您两次输入的密码不一致,请重新输入");
}
}
}
/**
* 登录
*/
public void dl() {
System.out.println("欢迎登录中国银行");
Scanner sc = new Scanner(System.in);
boolean pd = true;
boolean pd2 = true;
while (pd) {
System.out.println("请输入您的账号:");
int account = sc.nextInt();
// 遍历判断
for (zcUser zc : zcr1) {
if (zc.account != account) {
System.out.println("您输入的账号不存在,请重新输入!");
} else {
pd = false;
}
}
}
while (pd2) {
System.out.println("请输入您的密码:");
int pwd = sc.nextInt();
// 遍历判断
for (zcUser zc : zcr1) {
if (zc.pwd == pwd ) {
System.out.println("登陆成功");
pd2 = false;
} else {
System.out.println("密码错误,请重新输入!");
}
}
}
}
/**
* 选择登录还是注册
*/
public void xz() {
System.out.println("中国银行欢迎您\n1:登录\n2: 注册");
Scanner sc = new Scanner(System.in);
System.out.println("请选择操作:");
int x = sc.nextInt();
if(x==1) {
if(Z.account!=0) {
dl();
}else {
System.out.println("您还未注册,请先进行注册");
zc();
}
}else {
zc();
}
}
}
zcUser:
package atm;
/**
* 人员信息
* @author 王炳祥
*
*/
public class zcUser {
public int account=0;
public int pwd;
public zcUser() {
}
public zcUser(int account,int pwd) {
this.account=account;
this.pwd=pwd;
}
}
caozuo:
package atm;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
* 登录成功后选择的操作
*
* @author 王炳祥
*
*/
public class caozuo {
cunkuan C = new cunkuan();
// 创建存款的集合cunk
public List<cunkuan> cunk = new ArrayList<cunkuan>();
// 创建取款的集合cunk
public List<qukuan> quk = new ArrayList<qukuan>();
//
public void cz() {
boolean pd = true;
System.out.println("可执行的操作\n1:查询\n2:取款\n3:存款\n4:退卡");
// 利用循环,执行不同的操作
while (pd) {
System.out.print("请选择您要进行的操作:");
Scanner sc = new Scanner(System.in);
switch (sc.nextInt()) {
case 1:
chaxun();
pd = false;
break;
case 2:
qukuan();
pd = false;
// if(cunk.get(0).ck!=0) {
// qukuan();
// }
// else {
// System.out.println("余额不足,请进行充值");
// cunkuan();
// }
break;
case 3:
cunkuan();
pd = false;
break;
case 4:
tuika();
pd = false;
break;
default:
System.out.println("您输入的操作不存在,请重新输入");
}
}
}
/**
* 查询
*/
public void chaxun() {
boolean pd = true;
Scanner sc = new Scanner(System.in);
while (pd) {
System.out.println("请选择查询的信息操作\n1:账户余额\n2:账户流水");
int xxcz = sc.nextInt();
if (xxcz == 1) {
if (C.ck != 0) {
pd = false;
System.out.println("此卡余额为:" + (cunk.get(0).ck - quk.get(0).qk));
cz();
} else {
System.out.println("此卡还未存钱,余额为0");
cz();
}
} else {
if (xxcz == 2) {
if (C.ck != 0) {
pd = false;
System.out.println("该账户的流水存款:" + cunk.get(0).ck + "取款:" + quk.get(0).qk);
cz();
}else {
System.out.println("此卡还未进行充值激活");
cz();
}
} else {
System.out.println("您选择的操作不存在,请重新输入");
}
}
}
}
/**
* 存款方法
*/
public void cunkuan() {
System.out.println("请输入存款金额:");
Scanner sc = new Scanner(System.in);
// int jinE =sc.nextInt();
// 将输入的值存入集合,在用temp接收 此时temp接收的是地址
cunkuan ck = new cunkuan(sc.nextInt());
cunk.add(ck);
cunkuan temp = cunk.get(0);
System.out.println("存款成功,金额为:" + temp.ck);
cz();
}
/**
* 取款方法
*
*/
public void qukuan() {
if (C.ck != 0) {
System.out.println("请输入取款金额:");
Scanner sc = new Scanner(System.in);
qukuan qk = new qukuan(sc.nextInt());
quk.add(qk);
qukuan temp = quk.get(0);
if (quk.get(0).qk < cunk.get(0).ck) {
System.out.println("取款成功,余额为:" + (cunk.get(0).ck - quk.get(0).qk));
cz();
} else {
System.out.println("你还需要继续奋斗!");
cz();
}
} else {
System.out.println("账户还未存钱,请重新选择操作");
cz();
}
}
/**
* 退卡方法
*/
public void tuika() {
System.out.println("退卡成功,请取走您的卡片");
}
}
index:
package atm;
/**
* 功能实现主界面
* @author 王炳祥
*
*/
public class index {
public static void main(String[] args) {
// TODO Auto-generated method stub
login lo = new login();
caozuo cz = new caozuo();
lo.xz();
cz.cz();
}
}
cunkuan:
package atm;
/**
* 存款信息
* @author 王炳祥
*
*/
public class cunkuan {
public int ck = 0;
//无参构造器
public cunkuan() {
}
//含参构造器
public cunkuan (int ck) {
this.ck=ck;
}
}
qukuan:
package atm;
public class qukuan {
public int qk=0;
//无参构造器
public qukuan() {
}
//含参构造器
public qukuan (int qk) {
this.qk=qk;
}
}