Java编写ATM代码 用java编写atm取款机
java atm机代码
package arraylist;
创新互联主要从事网页设计、PC网站建设(电脑版网站建设)、wap网站建设(手机版网站建设)、成都响应式网站建设公司、程序开发、网站优化、微网站、微信小程序等,凭借多年来在互联网的打拼,我们在互联网网站建设行业积累了丰富的网站制作、做网站、网站设计、网络营销经验,集策划、开发、设计、营销、管理等多方位专业化运作于一体。
import java.util.Scanner;
public class AtmDemo
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
Boolean flag = true;
int times = 0;
while(flag){
times++;
if(times == 4){
System.out.println("密码错误,请取卡");
break;
}
System.out.println("请输入你的密码");
String password = sc.next();
if(password.equals("111111")){
Boolean moneyflag = true;
while(moneyflag){
System.out.println("请输入金额");
int number = sc.nextInt();
if(number = 0 number = 1000 number % 100 == 0){
System.out.println("用户取了" + number + "元。交易完成");
moneyflag = false;
}else{
System.out.println("请重新输入金额");
}
}
break;
}else{
continue;
}
}
}
}
java ATM登陆循环代码?
下面是一个简单的登录示例:
代码复制展示:
public class ATMLogin {
public static void main(String[] args) {
// 设置用户名和密码
String username = "gqk";
String password = "520";
// 最多可以登录 3 次
for (int i = 0; i 3; i++) {
// 读取用户输入的用户名和密码
Scanner in = new Scanner(System.in);
System.out.print("请输入用户名:");
String inputUsername = in.nextLine();
System.out.print("请输入密码:");
String inputPassword = in.nextLine();
// 检查用户名和密码是否正确
if (inputUsername.equals(username) inputPassword.equals(password)) {
System.out.println("欢迎" + username + "登录!");
break; // 登录成功,退出循环
} else {
System.out.println("用户名或密码错误,请重新输入!");
}
}
// 如果 3 次登录都失败,则提示用户
System.out.println("卡片已经被锁,请联系客服人员!");
}
}
回答不易望请采纳
java编写的模拟ATM取款机程序
我现写的: import java.util.Scanner;public class ATM {
private static String theName = "admin";
private static String thePassword = "123456";
private static int balance = 10000;
public static void getBalance(){
System.out.println("当前余额:" + balance);
}
public static void drawMoney(Scanner sc){
int money = 0;
System.out.println("请输入取款金额:");
money = sc.nextInt();
String type = "";
if (balance 0) {
if (balance = money) {
if (money = 5000) {
balance = balance - money;
type = "请在30秒内提取现金...\n剩余余额:"+balance;
} else if (money = 0) {
type = "金额错误";
} else {
type = "超出最大限制金额";
}
} else {
type = "超出最大余额";
}
} else {
type = "余额不足";
}
System.out.println(type);
}
public static void bankMoney(Scanner sc){
int money = 0;
System.out.println("请输入存储金额:");
money = sc.nextInt();
String type = "";
if (money 0) {
balance = balance + money;
type = "存储成功,现有余额:" + balance;
} else {
type = "存储金额不能为负";
}
System.out.println(type);
}
public static void updatePass(Scanner sc){
String oldPass = "";
String newPass1 = "";
String newPass2 = "";
while(true){
System.out.println("请输入原密码:");
oldPass = sc.next();
if (oldPass.equals(thePassword)) {
break;
} else {
System.out.println("密码错误,请重新输入");
}
}
while(true){
System.out.println("请输入新密码");
newPass1 = sc.next();
System.out.println("再次输入");
newPass2 = sc.next();
if (newPass1.equals(newPass2)) {
if (!isSame(newPass1)) {
thePassword = newPass1;
System.out.println("修改成功");
break;
} else {
System.out.println("所有字符不能相同,重新输入");
}
} else {
System.out.println("两次输入不一致,重新输入");
}
}
}
public static boolean isSame(String string){
boolean bool = false;
for (int i = 0; i string.length() - 1; i++) {
char char1 = string.charAt(i);
for (int j = i + 1; j string.length(); j++) {
char char2 = string.charAt(j);
if (char1 == char2) {
bool = true;
break;
}
}
}
return bool;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(true){
String name = "";
String password = "";
System.out.println("请输入账号:");
name = sc.next();
System.out.println("请输入密码:");
password = sc.next();
if (name.equals(theName) password.equals(thePassword)) {
break;
} else {
System.out.println("账号或密码错误,请重新输入!");
}
}
while(true){
int operate = 0;
System.out.println("请选择你要进行的操作:\n1、查询 2、取款 3、存款 4、修改密码 0、退出");
operate = sc.nextInt();
if (0 == operate) {
System.out.println("谢谢使用!");
break;
} else if (1 == operate) {
getBalance();
} else if (2 == operate) {
drawMoney(sc);
} else if (3 == operate) {
bankMoney(sc);
} else if (4 == operate) {
updatePass(sc);
}
}
}
}
网站标题:Java编写ATM代码 用java编写atm取款机
标题路径:http://ybzwz.com/article/ddijhjg.html