import java.io.FileReader;
import java.io.FileWriter;
import java.util.Properties;
import javax.swing.JOptionPane;
public class wwwwww {
public static void main(String[] args) {
Properties pro = new Properties();
try {
pro.load(new FileReader("money.txt"));
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "文件没有找到!");
}
String userNameStr = pro.getProperty("userName");
String pwdStr = pro.getProperty("pwd");
String nowmoneyStr = pro.getProperty("money");
int nowmoney = Integer.parseInt(nowmoneyStr);
JOptionPane.showMessageDialog(null, "欢迎光临");
boolean isLand = login(userNameStr, pwdStr);
if (isLand == false) {
JOptionPane.showMessageDialog(null, "非法用户");
System.exit(0);
}
while (true) {
String str = JOptionPane.showInputDialog(null,
"1、存款\n2、取款\n3、查询\n4、改密\n5、退出");
int i = Integer.parseInt(str);
switch (i) {
case 1:
nowmoney += save();
write(nowmoney);
break;
case 2:
nowmoney -= getmoney();
write(nowmoney);
break;
case 3:
refer(nowmoney);
break;
case 4:
writepwd(change(pwdStr));
break;
case 5:
System.exit(0);
break;
default:
JOptionPane.showMessageDialog(null, "请输入命令1--5");
}
}
}
// 登录
public static boolean login(String userNameStr, String pwdStr) {
for (int i = 0; i < 3; i++) {
String userName = JOptionPane.showInputDialog(null, "请输入用户名:");
String pwd = JOptionPane.showInputDialog(null, "请输入密码:");
if (userNameStr.equals(userName) && pwdStr.equals(pwd)) {
return true;
} else {
JOptionPane.showMessageDialog(null, "用户名或密码错误");
}
}
return false;
}
// 存款
public static int save() {
String getmoneyStr = JOptionPane.showInputDialog(null, "请输入存款金额");
int m = Integer.parseInt(getmoneyStr);
if (m > 10000) {
JOptionPane.showMessageDialog(null, "单次最多存10000元");
m = 0;
} else if (m < 0) {
System.out.println("存款应大于0");
m = 0;
} else if (m % 100 != 0) {
System.out.println("存款只能为100的整数倍");
m = 0;
} else {
JOptionPane.showMessageDialog(null, "存款成功!");
}
return m;
}
// 取款
public static int getmoney() {
String getmoney = JOptionPane.showInputDialog(null, "请输入取款金额:");
int g = Integer.parseInt(getmoney);
Properties pro = new Properties();
try {
pro.load(new FileReader("money.txt"));
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "文件没有找到!");
}
String nowmoneyStr = pro.getProperty("money");
int nowmoney = Integer.parseInt(nowmoneyStr);
if (g > 5000) {
JOptionPane.showMessageDialog(null, "单次最多取5000.00元");
g = 0;
} else if (g < 0) {
JOptionPane.showMessageDialog(null, "请输入正数金额");
g = 0;
} else if (g % 100 != 0) {
JOptionPane.showMessageDialog(null, "存款只能取100的整数倍");
g = 0;
} else if (g > nowmoney) {
JOptionPane.showMessageDialog(null, "余额不足!");
g = 0;
} else {
JOptionPane.showMessageDialog(null, "取款成功!");
}
return g;
}
// 查询
public static void refer(int nowmoney) {
JOptionPane.showMessageDialog(null, "你的余额为:" + nowmoney);
}
/**
* 改密
* */
public static String change(String pwdStr) {
String inputpwd = JOptionPane.showInputDialog(null, "请输旧老密码:");
if (inputpwd.equals(pwdStr)) {
// 旧密码正确
String newPwd = JOptionPane.showInputDialog(null, "请输入新密码");
String newPwd2 = JOptionPane.showInputDialog(null, "请再次输入新密码");
if (newPwd.equals(newPwd2)) {
JOptionPane.showMessageDialog(null, "密码修改成功!");
return newPwd;
} else {
JOptionPane.showMessageDialog(null, "两次密码不一致!请重新设置!");
return pwdStr;
}
} else {
JOptionPane.showMessageDialog(null, "旧密码错误!");
}
return pwdStr;
}
// 写入方法
public static void write(int k) {
Properties pro = new Properties();
try {
pro.load(new FileReader("money.txt"));
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "文件没有找到!");
}
pro.setProperty("money", k + "");
try {
pro.store(new FileWriter("money.txt"), null);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "文件没有找到!");
}
}
// 密码修改方法
public static void writepwd(String j) {
Properties pro = new Properties();
try {
pro.load(new FileReader("money.txt"));
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "文件没有找到!");
}
pro.setProperty("pwd", j + "");
try {
pro.store(new FileWriter("money.txt"), null);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "文件没有找到!");
}
}
import java.io.FileWriter;
import java.util.Properties;
import javax.swing.JOptionPane;
public class wwwwww {
public static void main(String[] args) {
Properties pro = new Properties();
try {
pro.load(new FileReader("money.txt"));
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "文件没有找到!");
}
String userNameStr = pro.getProperty("userName");
String pwdStr = pro.getProperty("pwd");
String nowmoneyStr = pro.getProperty("money");
int nowmoney = Integer.parseInt(nowmoneyStr);
JOptionPane.showMessageDialog(null, "欢迎光临");
boolean isLand = login(userNameStr, pwdStr);
if (isLand == false) {
JOptionPane.showMessageDialog(null, "非法用户");
System.exit(0);
}
while (true) {
String str = JOptionPane.showInputDialog(null,
"1、存款\n2、取款\n3、查询\n4、改密\n5、退出");
int i = Integer.parseInt(str);
switch (i) {
case 1:
nowmoney += save();
write(nowmoney);
break;
case 2:
nowmoney -= getmoney();
write(nowmoney);
break;
case 3:
refer(nowmoney);
break;
case 4:
writepwd(change(pwdStr));
break;
case 5:
System.exit(0);
break;
default:
JOptionPane.showMessageDialog(null, "请输入命令1--5");
}
}
}
// 登录
public static boolean login(String userNameStr, String pwdStr) {
for (int i = 0; i < 3; i++) {
String userName = JOptionPane.showInputDialog(null, "请输入用户名:");
String pwd = JOptionPane.showInputDialog(null, "请输入密码:");
if (userNameStr.equals(userName) && pwdStr.equals(pwd)) {
return true;
} else {
JOptionPane.showMessageDialog(null, "用户名或密码错误");
}
}
return false;
}
// 存款
public static int save() {
String getmoneyStr = JOptionPane.showInputDialog(null, "请输入存款金额");
int m = Integer.parseInt(getmoneyStr);
if (m > 10000) {
JOptionPane.showMessageDialog(null, "单次最多存10000元");
m = 0;
} else if (m < 0) {
System.out.println("存款应大于0");
m = 0;
} else if (m % 100 != 0) {
System.out.println("存款只能为100的整数倍");
m = 0;
} else {
JOptionPane.showMessageDialog(null, "存款成功!");
}
return m;
}
// 取款
public static int getmoney() {
String getmoney = JOptionPane.showInputDialog(null, "请输入取款金额:");
int g = Integer.parseInt(getmoney);
Properties pro = new Properties();
try {
pro.load(new FileReader("money.txt"));
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "文件没有找到!");
}
String nowmoneyStr = pro.getProperty("money");
int nowmoney = Integer.parseInt(nowmoneyStr);
if (g > 5000) {
JOptionPane.showMessageDialog(null, "单次最多取5000.00元");
g = 0;
} else if (g < 0) {
JOptionPane.showMessageDialog(null, "请输入正数金额");
g = 0;
} else if (g % 100 != 0) {
JOptionPane.showMessageDialog(null, "存款只能取100的整数倍");
g = 0;
} else if (g > nowmoney) {
JOptionPane.showMessageDialog(null, "余额不足!");
g = 0;
} else {
JOptionPane.showMessageDialog(null, "取款成功!");
}
return g;
}
// 查询
public static void refer(int nowmoney) {
JOptionPane.showMessageDialog(null, "你的余额为:" + nowmoney);
}
/**
* 改密
* */
public static String change(String pwdStr) {
String inputpwd = JOptionPane.showInputDialog(null, "请输旧老密码:");
if (inputpwd.equals(pwdStr)) {
// 旧密码正确
String newPwd = JOptionPane.showInputDialog(null, "请输入新密码");
String newPwd2 = JOptionPane.showInputDialog(null, "请再次输入新密码");
if (newPwd.equals(newPwd2)) {
JOptionPane.showMessageDialog(null, "密码修改成功!");
return newPwd;
} else {
JOptionPane.showMessageDialog(null, "两次密码不一致!请重新设置!");
return pwdStr;
}
} else {
JOptionPane.showMessageDialog(null, "旧密码错误!");
}
return pwdStr;
}
// 写入方法
public static void write(int k) {
Properties pro = new Properties();
try {
pro.load(new FileReader("money.txt"));
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "文件没有找到!");
}
pro.setProperty("money", k + "");
try {
pro.store(new FileWriter("money.txt"), null);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "文件没有找到!");
}
}
// 密码修改方法
public static void writepwd(String j) {
Properties pro = new Properties();
try {
pro.load(new FileReader("money.txt"));
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "文件没有找到!");
}
pro.setProperty("pwd", j + "");
try {
pro.store(new FileWriter("money.txt"), null);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "文件没有找到!");
}
}
}
在根目录下新建一个money.txt文件
userName=java
money=3000
pwd=123