import java.util.Scanner
public class ATM {
/大拦配**
* @param args
*/
public static void main(String[] args) {
Scanner in = null
int result
double drawMoney
double depositMoney
Account account = new Account()
while (true) {
System.out.println("☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆(ABC)中国农业银行ATM自动存取款机☆☆☆☆☆☆☆☆☆☆☆☆☆")
System.out.println("\n\t\t\t\t1.存款业务")
System.out.println("\n\t\t\t\t2.取款业务")
System.out.println("\n\t\t\t\t3.查询余额")
System.out.println("\n\t\t\t\t4.退出ATM系统")
System.out.println("\n☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆中国农业银行欢迎您的使用☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆")
in = new Scanner(System.in)
switch (in.nextInt()) {
case 1:
System.out.println("请输入您的存款数额!")
depositMoney = in.nextDouble()
if(depositMoney <0)
System.out.println("您的输入无效,请重新输入!")
result = account.deposit(depositMoney)
if(result == 0){
System.out.println("存款业务完成,是否显示余额?Y/N")
if("Y".equalsIgnoreCase(in.next())){
System.out.println("您当前的余额为:"+account.checkCurrent())
}else {
break
}
}else {
System.out.println("无法完成交易!")
break
}
break
case 2:
System.out.println("请输入您的取款滚指数额!")
drawMoney = in.nextDouble()
if (drawMoney <0) {
System.out.println("您的输入无效,请衡乎重新输入!")
}
result = account.withDraw(drawMoney)
if (result == 0) {
System.out.println("存款业务完成,是否显示余额?Y/N")
if("Y".equalsIgnoreCase(in.next())){
System.out.println("您当前的余额为:"+account.checkCurrent())
}else {
break
}
} else {
System.out.println("无法完成交易!")
break
}
case 3:
System.out.println("您当前的余额为:"+account.checkCurrent())
break
case 4:
break
default:
break
}
}
}
}
public class Account {
private double currentMoney//当前余额
public double getCurrentMoney() {
return currentMoney
}
public void setCurrentMoney(double currentMoney) {
if (currentMoney >0) {
this.currentMoney = currentMoney
}
}
/**
* 取款业务
* @param drawMoney
* @return 0代表成功,1代表失败
*/
public int withDraw(double drawMoney) {
if (currentMoney >0 &&drawMoney <= currentMoney) {
currentMoney -= drawMoney
} else {
System.out.println("您的余额已不足!")
return 1
}
return 0
}
/**
* 存款业务
* @param depositMoney
* @return 0代表成功,1代表失败
*/
public int deposit(double depositMoney) {
if (depositMoney >0) {
currentMoney += depositMoney
return 0
}else {
System.out.println("您提交的存款为负数,无法完成存款交易")
return -1
}
}
/**
* 查询余额业务
* @return
*/
public double checkCurrent() {
return currentMoney
}
}
/**要求:使用字符用户界面。当输入给定的卡号和密码(初始卡号和密码为123456)时,系统能登录ATM柜员机系统,用户可以按照以下规则进行:
1、查询余额:初始余额为10000元
2、ATM取款:每次取款金额为100的倍数,总额不超过5000元,支取金额不允许透支。
3、ATM存款:不能出现负存款。
4、修改密码:新密码长度不小于6位,不允许出现6位完全相同的情况,只有旧密码正确,新密码符合要求,且两次输入相同的情况下才可以成功修改密码。
(卡号密码余额放到文件中)
*/
public class Test {
private static int account
private static int password
private static int money
private static 粗拿棚boolean isLogin
static{
account = 123456
password = 123456
money = 10000
isLogin = false
}
//存款
public void cun(int cunKuan){
if(cunKuan>=0){
this.money += cunKuan
}else{
System.out.println("存款不能为负!")
}
}
//取款
public void qu(int quKuan){
if(this.money - quKuan < 0){
System.out.println("余额不足!")
return
}
if(isValid(quKuan)){
this.money -= quKuan
}else{
System.out.println("取款不能为负,且应为100的倍数!")
}
}
//判断是否为有效的金额
private boolean isValid(int money){
if(money >= 0 && money % 100 == 0){
return true
}
return false
}
//登陆
public void login(){
System.out.println("请输入账号和密码【格式为:账号/密码】")
String login = new Scanner(System.in).next()
if(login.equalsIgnoreCase("123456/123456")){
this.isLogin = true
}else{
System.out.println("账号或者密码错误,请重新输入!")
login()
}
岩则 }
//主菜单
public void show(){
System.out.println("[1]存款")
System.out.println("[2]取款")
System.out.println("[3]退出")
System.out.println("请输入:")
int key = new Scanner(System.in).nextInt()
switch (key) {
敏物 case 1:
cun(new Scanner(System.in).nextInt())
break
case 2:
qu(new Scanner(System.in).nextInt())
break
case 3:
System.exit(0)
default:
break
}
}
public static void main(String[] args) {
Test t = new Test()
t.login()
if(t.isLogin){
for(){
t.show()
System.out.println("您当前的余额为:" + t.money)
}
}
}
}
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)
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)