标签:
package sf;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.Properties;
import javax.swing.JOptionPane;
public class ATM {
public static Properties zhmm = new Properties();
public static void main(String[] args) {
JOptionPane.showMessageDialog(null, "欢迎光临");
// 调用读取密码文档
dq();
for (int i = 0; i < 3; i++){
String namstr = JOptionPane.showInputDialog(null, "输入用户名");
String pwdstr = JOptionPane.showInputDialog(null, "请输入密码");
int m = Integer.parseInt(pwdstr);
//三次输入密码循环
if (namstr.equals(zhmm.getProperty("code"))
&& pwdstr.equals(zhmm.getProperty("number"))) {
// 调用主界面方法
zjm();
} else {
JOptionPane.showMessageDialog(null, "用户名或密码错误");
}
}
JOptionPane.showMessageDialog(null, "非法用户");
System.exit(0);
}
// 主界面方法
public static void zjm() {
while (true) {
String xz = JOptionPane.showInputDialog(null,
"1、存款\n2、取款\n3、查询\n4、改密\n5、退出");
int x = Integer.parseInt(xz);
switch (x) {
case 1:
ck();
break;
case 2:
qk();
break;
case 3:
cx();
break;
case 4:
gm();
break;
case 5:
System.exit(0);
}
}
}
public static void gm() {
String str = JOptionPane.showInputDialog(null, "输入新密码");
String stri = JOptionPane.showInputDialog(null, "再次输入");
int pwd1 = Integer.parseInt(str);
int pwd2 = Integer.parseInt(stri);
if (pwd1 == pwd2) {
zhmm.setProperty("number", pwd1 + "");
JOptionPane.showMessageDialog(null, "修改成功");
lr();
} else {
JOptionPane.showMessageDialog(null, "输入密码不一致");
}
}
// 查询
public static void cx() {
JOptionPane.showMessageDialog(null, zhmm.getProperty("money"));
}
// 1存款方法
public static void ck() {
String money = JOptionPane.showInputDialog(null, "输入存款金额");
int m1 = Integer.parseInt(money);
int m2 = Integer.parseInt(zhmm.getProperty("money"));
m2 = m1 + m2;
zhmm.setProperty("money", m2 + "");
}
// 2取款方法
public static void qk() {
String money = JOptionPane.showInputDialog(null, "输入取款金额");
int m1 = Integer.parseInt(money);
int newm = Integer.parseInt(zhmm.getProperty("money"));
if (newm > m1) {
newm = newm - m1;
zhmm.setProperty("money", newm + "");
} else {
JOptionPane.showMessageDialog(null, "超支鸟");
}
}
// 读取用户名和密码方法
public static void dq() {
try {
zhmm.load(new FileReader("mm.txt"));
} catch (Exception e) {
System.out.print("顶顶顶顶顶顶顶");
}
}
// 录入修改数据
public static void lr() {
try {
zhmm.store(new FileWriter("mm.txt"), null);
} catch (Exception e) {
System.out.print("顶顶顶顶顶顶顶");
}
}
}
标签:
原文地址:http://www.cnblogs.com/tujoin/p/4559984.html