1. atm機的java怎麼寫啊
package demo;
import java.io.*;
/*該類為實現客戶信息及部分功能*/
class Account {
private String code =null; //信用卡號
private String name =null; //客戶姓名
private String password=null; //客戶密碼
private double money =0.0; //卡里金額
/********************/
public Account(String code,String name,String password,double money)
{
this.code=code;
this.name=name;
this.password=password;
this.money=money;
}
protected String get_Code() {
return code;
}
protected String get_Name() {
return name;
}
protected String get_Password() {
return password;
}
public double get_Money() {
return money;
}
/*得到剩餘的錢的數目*/
protected void set_Balance(double mon) {
money -= mon;
}
/*得到剩餘的錢的數目*/
protected void set_Deposit(double mon) {
money += mon;
}
}
/**********實現具體取款機功能*********/
class ATM {
Account act;
// private String name;
// private String pwd;
public ATM() {
act=new Account("000000","Devil","123456",50000);
}
/***********歡迎界面***********/
protected void Welcome()
{
String str="---------------------------------";
System.out.print(str+"\n"+
"歡迎使用Angel模擬自動取款機程序.\n"+str+"\n");
System.out.print(" 1.>取款."+"\n"+
" 2.>存款."+"\n"+
" 3.>查詢信息."+"\n"+
" 4.>密碼設置."+"\n"+
" 5.>退出系統."+"\n");
}
/**********登陸系統**********/
protected void Load_Sys() throws Exception
{
String card,pwd;
int counter=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
do {
System.out.println("請輸入您的信用卡號:");
card=br.readLine();
System.out.println("請輸入您的密碼:");
pwd=br.readLine();
if(!isRight(card,pwd))
{
System.out.println("您的卡號或密碼輸入有誤.");
counter++;
}
else
Welcome();
SysOpter();
}while(counter<3);
Lock_Sys();
}
/**********系統操作**********/
protected void SysOpter() throws Exception
{
int num;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("請選擇您要操作的項目(1-5):");
num=br.read(); //num為ASICC碼轉換的整數
switch(num) {
case 49: BetBalance(); break;
case 50: Deposit(); break;
case 51: Inqu_Info(); break;
case 52: Set_Password(); break;
case 53: Exit_Sys(); break;
}
System.exit(1);
}
/**********信息查詢
* @throws Exception **********/
protected void Inqu_Info() throws Exception {
System.out.print("---------------------\n"+
act.get_Code()+"\n"+
act.get_Name()+"\n"+
act.get_Money()+"\n"+
"-----------------------");
Welcome();
SysOpter();
}
/**********取款**********/
public void BetBalance() throws Exception
{
String str=null,str1;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int count=0;//取款錯誤超過3次自動退出
do {
System.out.println("請輸入您要取的數目:");
str=br.readLine();
str1=String.valueOf(act.get_Money());
System.out.println(str1);
if(Double.parseDouble(str)>Double.parseDouble(str1)) {
count++;
System.out.println("超過已有的錢數,請重新輸入您要取的數目:");
if(count>=3){
System.out.println("超過已有的錢數,請重新輸入您要取的數目:");
Exit_Sys();
}
}
else {
/*操作成功*/
act.set_Balance(Double.parseDouble(str));
System.out.println("取款成功,請收好您的錢.");
Welcome();
SysOpter();
}
}while(true);
}
/*******存款********/
public void Deposit() throws Exception{
String str=null;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
do {
System.out.println("請輸入您要存的數目:");
str=br.readLine();
/*操作成功*/
act.set_Deposit(Double.parseDouble(str));
System.out.println("取款成功,請收好您的錢.");
Welcome();
SysOpter();
}while(true);
}
/**********判斷卡內是否有錢**********/
protected boolean isBalance() {
if(act.get_Money()<0) {
System.out.println("對不起,您的錢數不夠或卡已透支.");
return false;
}
return true;
}
/********卡號密碼是否正確******/
protected boolean isRight(String card,String pwd)
{
if(act.get_Code().equals(card) && act.get_Password().equals(pwd))
return true;
else
return false;
}
/**********密碼修改**********/
protected void Set_Password() throws Exception
{
String pwd=null;
int counter=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
do {
System.out.println("請輸入舊密碼:");
pwd=br.readLine();
if(act.get_Password().equals(pwd))
{
do {
System.out.println("請輸入新密碼:");
String pwd1=br.readLine();
System.out.println("請再次輸入新密碼:");
String pwd2=br.readLine();
if(!pwd1.equals(pwd2))
{
System.out.println("兩次輸入不一致,請再次輸入.");
}
else
{
System.out.println("密碼修改成功,請使用新密碼.");
Welcome();
SysOpter();
}
}while(true);
}
}while(counter>3);
}
/**********鎖定機器**********/
protected void Lock_Sys() {
System.out.println("對不起,您的操作有誤,卡已被沒收.");
System.exit(1);
}
/**********結束系統**********/
protected void Exit_Sys() {
System.out.println("感謝您使用本系統,歡迎下次在來,再見!");
System.exit(1);
}
}
public class Text
{
public static void main(String[] args) throws Exception
{
ATM atm=new ATM();
atm.Load_Sys();
// atm.Exit_Sys();
}
}
卡號:00000 密碼123456 默認50000金額。簡單版本的存取款。
2. java atm機代碼
package arraylist;
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;
}
}
}
}
3. 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);
}
}
}
}
4. 用java做一個簡易的ATM機具體流程在下面
代碼如下
packageBaiD;
importjava.util.Scanner;
publicclassATM{
/*1提示請輸入密碼然後直接進入下一步。密碼6位限制(限制方法用「最小大於100000最大小於999999」這樣限制)
2.提示密碼正確還是錯誤密碼直接弄成「123456」錯誤返回上一步循環方法用for循環。
3.密碼輸入正確後進入下一步提示5個選項(1.余額查詢「基礎10000」2.取款3存款4.退出)
4.進行取款或者存款之後要回到第三步重新選擇(余額和取款存款相關聯)
備註:用鍵盤輸入的方法用scanner*/
privatestaticintmoney=10000;//全局變數余額默認10000
publicstaticvoidmain(Stringargs[])
{
for(;;){//for循環,有意思嗎?
System.out.println("請輸入密碼:");
Scannerinput=newScanner(System.in);
intpw=input.nextInt();
if(Checkpw(pw)){
System.out.println("密碼正確。");
Next();
}
elseSystem.out.println("密碼錯誤!");
}
}
publicstaticbooleanCheckpw(intpw)
{
if(pw==123456)returntrue;//固定密碼就不需要限制位數了,反正不符合就錯
else
returnfalse;
}
publicstaticvoidNext(){
do{
System.out.println("請選擇你需要的功能:");
System.out.println("1.余額查詢2.取款3.存款4.退出");
intvalue=newScanner(System.in).nextInt();
switch(value){
case1://查詢余額
System.out.println("您的余額為"+money+"元");
break;
case2://取款
System.out.println("請輸入取款金額:");
intgetnum=newScanner(System.in).nextInt();
if(getnum<0)System.out.println("輸入金額有誤!");
elseif(getnum>money)System.out.println("余額不足.");
else{money=money-getnum;System.out.println("取款成功,余額為"+money);}
break;
case3://存款
System.out.println("請輸入存款金額:");
intpushnum=newScanner(System.in).nextInt();
if(pushnum<0)System.out.println("輸入金額有誤!");
else{money=money+pushnum;System.out.println("存款成功,余額為"+money);}
break;
case4://退出
System.out.println("謝謝使用!");
System.exit(0);
break;
default:
System.out.println("輸入有誤");
break;
}
}while(true);
}
}
2、運行效果
5. Java編程實現程序用於模擬ATM取款機。
package demo;
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();
}
}
}
}
6. 求高手用JAVA編寫一個模擬ATM機取款業務需求如下:
樓主您好,編碼如下,直接運行即可:
import java.util.Scanner;
public class AtmGetMoney {
public static void main(String[] args) {
String password = "111111";
int count = 0;
int a = 0;
while(count<3){
System.out.println("請輸入銀行卡密碼: ");
Scanner scan = new Scanner(System.in);
String passwd = scan.nextLine();
while(passwd.equals(password)){
System.out.println("請輸入取款金額: ");
int amount = scan.nextInt();
if(amount%100 == 0 && amount <= 1000){
System.out.println("您的取款金額為: "+amount);
System.out.println("交易完成,請讀卡!");
a = a + 1;
break;
}
else {
System.out.println("只能提取100元紙幣,要求最低0,最高1000!");
continue;
}
}
if (a == 1){
break;
}
else if (count < 2) {
System.out.println("銀行卡密碼錯誤");
count = count + 1;
continue;
}
else {
System.out.println("密碼錯誤請讀卡");
break;
}
}
}
}