import java.util.Scanner
public class Test3 {
public static void main(String[] args) {
Scanner scanner =new Scanner(System.in)
int cnt=3
String username = null
String password = null
double money = 1000
String targetName = "admin33"
double targetMoney = 1000
while(true){
if(username!=null&&password!=null){
if("游滑admin".equals(username) &&"123".equals(password)){
System.out.println("欢迎光临")
while(true){
System.out.println("请选择您的 *** 作 1 取钱 2 存钱 3 转账 4 查询 5 退出 ")
int n = scanner.nextInt()
if(n==1){//取钱
System.out.println("请输入金额")
int getter = scanner.nextInt()
if(getter>=0){
if(getter<=5000){
if(getter<=money){
money-=getter
}else{
System.out.println("余额不足")
}
}else{
System.out.println("单笔只能取5000及以下")
}
}else{
System.out.println("银行不到给")
}
}else if(n==2){//存钱
System.out.println("请输入金额")
int save = scanner.nextInt()
if(save>=0){
money+=save
}
}else if(n==3){//转账
System.out.println("请输入目行磨粗标账户")
String target = scanner.next()
if(target.equals(targetName)){
System.out.println("请输入金额")
int getter = scanner.nextInt()
if(getter>=0){
if(getter<=5000){
if(getter<=money){
money-=getter
targetMoney+=getter
}else{
System.out.println("余额不足")
}
}else{
System.out.println("单笔只能取5000及以下")
}
}else{
System.out.println("银行不到给")
}
}
}else if(n==4){//查询
System.out.println(money)
}else if(n==5){//退出
System.exit(0)
}else{
System.out.println("没有该项服务")
}
}
}else{
cnt--
System.out.println("输入错误,您还有"+cnt+"次档镇机会")
username=null
password=null
if(cnt<=0){
System.out.println("对不起,您的账号被冻结,请到最近的营业厅解除冻结")
System.exit(0)
}
}
}else{
System.out.println("请输入您的账号")
username = scanner.next()
System.out.println("请输入您的密码")
password = scanner.next()
}
}
}
}
import java.io.IOException
/**
* ATM机类
*
* 查看余额
*
* 取款
*
* 存款
*
* 退出系统
*
*
*
*/
public class ATM {
static double yue = 1200.00
public static void main(String[] arg) {
ATM localTest1 = new ATM()
localTest1.ATM_Operate()
}
/**
* ATM机的 *** 作
*/
private void ATM_Operate() {
System.out.println("欢中源亮迎使用中国工商银行ATM取款机")
System.out.println("1、查看余额 2、裂兆取款")
System.out.println("3、存款0、退出")
System.out.print("请输入您需要的服务:")
byte[] buffer = new byte[512]
try {
int count = System.in.read(buffer)// 返回实际读取的字节数
System.out.print("您输入的是:")
for (int i = 0i <counti++) {
System.out.print("" + (char) buffer[i])
}
if ((char) buffer[0] == '1') {
// 查看余额
System.out.println("您的余额是:¥" + yue + "元")
System.out.println()
ATM_Operate()
} else if ((char) buffer[0] == '2') {
// 取款
withdrawal()
System.out.println()
ATM_Operate()
} else if ((char) buffer[0] == '3') {
//卖宽 存款
deposit()
System.out.println()
ATM_Operate()
} else if ((char) buffer[0] == '0') {
// 退出
System.out.println("您已经成功退出系统,谢谢你的使用")
System.exit(0)
} else {
System.out.println("输入不合法,请重新输入")
System.out.println()
ATM_Operate()
}
} catch (IOException e) {
e.printStackTrace()
}
}
/**
* 取款
*
* @throws IOException
*/
private void withdrawal() throws IOException {
byte[] buffer = new byte[512]
System.out.print("请输入您要取出的金额:¥")
int count2 = System.in.read(buffer)// 返回实际读取的字节数
System.out.print("您输入的金额是:")
for (int i = 0i <count2 - 1i++) {
System.out.print("" + (char) buffer[i])
}
System.out.println()
// 字符0 ~ 9对应ASCII值48 ~ 57
boolean flag = false
for (int i = 0i <count2 - 1i++) {
if ((char) buffer[i] >47 &&(char) buffer[i] <58) {
if (i == count2 - 2) {
flag = true
}
} else {
// 输入的字符不是数值
System.out.println("输入不合法,请重新输入")
withdrawal()
break
}
}
System.out.println()
if (flag) {
System.out.print("您已成功取出¥:")
String num = ""
for (int i = 0i <count2 - 1i++) {
System.out.print("" + (char) buffer[i])
num += (char) buffer[i]
}
yue -= Double.valueOf(num)
System.out.print(",现在余额¥:" + yue)
}
}
/**
* 存款
*
* @throws IOException
*/
private void deposit() throws IOException {
byte[] buffer = new byte[512]
System.out.print("请输入您要存入的金额:¥")
int count2 = System.in.read(buffer)// 返回实际读取的字节数
System.out.print("您输入的金额是:")
for (int i = 0i <count2 - 1i++) {
System.out.print("" + (char) buffer[i])
}
System.out.println()
// 字符0 ~ 9对应ASCII值48 ~ 57
boolean flag = false
for (int i = 0i <count2 - 1i++) {
if ((char) buffer[i] >47 &&(char) buffer[i] <58) {
if (i == count2 - 2) {
flag = true
}
} else {
// 输入的字符不是数值
System.out.println("输入不合法,请重新输入")
withdrawal()
break
}
}
System.out.println()
if (flag) {
System.out.print("您已成功存入¥:")
String num = ""
for (int i = 0i <count2 - 1i++) {
System.out.print("" + (char) buffer[i])
num += (char) buffer[i]
}
yue += Double.valueOf(num)
System.out.print(",现在余额¥:" + yue)
}
}
}
ATM系统势必要把,安全性放在第一位,那么滚纯用Java的多线程以及锁可以解决多大猜咐用户 *** 作统一账户的情况,关于每登录进来一个账户,也可以写一个事件兆搜监听,关于异常也就是你说的取款记得要用同步锁(synchronized) ,还有什么不明白的吗欢迎分享,转载请注明来源:内存溢出
评论列表(0条)