atm取款機java課程設計
Ⅰ 使用Java語言進行面向對象設計:ATM櫃員機模擬程序
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class AtmSystem extends JFrame implements ActionListener
{
private JPanel buttonPanel=new JPanel();
private JPanel area1Panel=new JPanel();
private JPanel area2Panel=new JPanel();
private JTextField note=new JTextField(33);
private JButton buttons[];
private JButton dot = new JButton(".");
private JButton doublezero = new JButton("00");
private JButton ok = new JButton("確定");
private JButton exit = new JButton("退出");
private JButton cancel = new JButton("取消");
private JButton change=new JButton("更正");
private JButton getmoney = new JButton("取款");
private JButton search = new JButton("查詢余額");
private JButton changekey = new JButton("修改密碼");
private JButton putmoney= new JButton("存款");;
private boolean flag0, flag1, flag2,flag3,flag4;
int status=0;
int k,s,k1;
String str1="\t歡迎使用ATM櫃員機!";
String str2="\t請輸入用戶名:";
String str3="\t請輸入密碼:";
String str4="\t請輸入取款金額:";
String str5="\t請輸入存款金額:";
String str6="\t請輸入新密碼:";
String str7="\t您的余額為:";
String str8="\t用戶名錯誤,請重新輸入:";
String str9="\t密碼錯誤,請重新輸入:";
String str10="\t余額不足,請重新輸入:";
String str11="\t密碼修改成功!";
String store1="",store2="";
double moneysum=10000;
double getMoney;
String username="123456";
String password="123456";
public AtmSystem()
{
super("ATM櫃員機");
Container container=getContentPane();
buttons=new JButton[10];
dot.addActionListener(this);
doublezero.addActionListener(this);
change.addActionListener(this);
cancel.addActionListener(this);
ok.addActionListener(this);
exit.addActionListener(this);
changekey.addActionListener(this);
putmoney.addActionListener(this);
getmoney.addActionListener(this);
search.addActionListener(this);
area2Panel.add(changekey);
area2Panel.add(putmoney);
area2Panel.add(getmoney);
area2Panel.add(search);
area2Panel.setLayout(new GridLayout(1,3));
container.add(area2Panel,BorderLayout.NORTH);
note.setText(str1);
note.setEditable(false);
area1Panel.add(note);
buttonPanel.setLayout(new GridLayout(4,4));
for(int count=0;count<buttons.length;count++)
{
buttons[count]=new JButton(""+count);
buttons[count].addActionListener(this);
buttonPanel.add(buttons[count]);
}
buttonPanel.add(doublezero);
buttonPanel.add(dot);
buttonPanel.add(change);
buttonPanel.add(cancel);
buttonPanel.add(ok);
buttonPanel.add(exit);
container.add(buttonPanel,BorderLayout.SOUTH);
container.add(area1Panel);
area1Panel.setVisible(true);
area2Panel.setVisible(false);
setSize(400,250);
setVisible(true);
}
public void actionPerformed(ActionEvent event)
{
JButton operation = (JButton) event.getSource();
if(operation==ok)
{
if(status==0)
{
note.setText(""+str2);
status=1;
}
else if(flag4==true)
{
area2Panel.setVisible(true);
area1Panel.setVisible(false);
flag4=false;
}
else if(status==1&&k==1)
{
note.setText(""+str3);
status=2;
k=0;
}
else if(status==1&&k==0)
{
note.setText(""+str8);
store1="";
}
else if(status==2&&k1==1)
{
k1=0;
area1Panel.setVisible(false);
area2Panel.setVisible(true);
status=3;
}
else if(status==2&&k1==0)
{
note.setText(""+str9);
store2="";
}
else if(status==3)
{
if(flag0==true)
{
getMoney=Double.valueOf(store1).doubleValue();
if(getMoney<moneysum)
{
area2Panel.setVisible(true);
area1Panel.setVisible(false);
flag0=false;
moneysum=moneysum-getMoney;
}
else
{
area2Panel.setVisible(false);
area1Panel.setVisible(true);
note.setText(""+str10);
store1="";
}
}
else if(flag1==true)
{
area2Panel.setVisible(true);
area1Panel.setVisible(false);
flag1=false;
}
else if(flag2==true)
flag2=false;
else if(flag3=true)
{
flag4=true;
note.setText(""+str11);
password=store2;
flag3=false;
}
}
}
else if(operation==cancel)
{
if(status==1)
{
note.setText(""+str1);
status=0;
store1="";
store2="";
}
else if(status==2)
{
note.setText(""+str2);
status=1;
store1="";
store2="";
}
else if(status==3&&flag2)
{
area1Panel.setVisible(false);
area2Panel.setVisible(true);
flag2=false;
store1="";
store2="";
}
else if(status==3&&flag0)
{
area1Panel.setVisible(false);
area2Panel.setVisible(true);
flag0=false;
store1="";
store2="";
}
else if(status==3&&flag3)
{
area1Panel.setVisible(false);
area2Panel.setVisible(true);
flag3=false;
store1="";
store2="";
}
}
else if(operation==change)
{
if(status==1)
{
note.setText(""+str2);
store1="";
store2="";
}
else if(status==2)
{
note.setText(""+str3);
store1="";
store2="";
}
else if(status==3&&flag2)
{
note.setText(""+str5);
store1="";
store2="";
}
else if(status==3&&flag0)
{
note.setText(""+str4);
store1="";
store2="";
}
else if(status==3&&flag3)
{
note.setText(""+str6);
store1="";
store2="";
}
}
else if(operation==doublezero&&status==3&&flag0==true)
{
note.setText(note.getText()+"00");
}
else if(operation==dot&&status==3&&flag0==true)
{
note.setText(note.getText()+".");
}
else if(operation==getmoney)
{
note.setText(""+str4);
area2Panel.setVisible(false);
area1Panel.setVisible(true);
store1="";
flag0=true;
}
else if(operation==search)
{
note.setText(""+str7+moneysum);
area2Panel.setVisible(false);
area1Panel.setVisible(true);
flag1=true;
}
else if(operation==putmoney)
{
note.setText(""+str5);
area2Panel.setVisible(false);
area1Panel.setVisible(true);
flag2=true;
}
else if(operation==changekey)
{
note.setText(""+str6);
area2Panel.setVisible(false);
area1Panel.setVisible(true);
store2="";
flag3=true;
}
else if(operation==exit)
{
note.setText(""+str1);
area2Panel.setVisible(false);
area1Panel.setVisible(true);
status=0;
flag0=flag1=flag2=flag3=flag4=false;
store1="";
store2="";
k=k1=s=0;
}
else if(status==1||(status==3&&flag2==true)||(status==3&&flag0==true))
{
for(int count=0;count<buttons.length;count++)
if (operation== buttons[count])
{
note.setText(note.getText() + count);
store1+=event.getActionCommand();
}
user(store1);
}
else if(status==2||(status==3&&flag3==true))
{
for(int count=0;count<buttons.length;count++)
if (operation== buttons[count])
{
note.setText(note.getText()+ "*");
store2+=event.getActionCommand();
}
key(store2);
}
}
public void user(String load)
{
if(username.equals(load))
{
k=1;
s=1;
}
}
public void key(String load)
{
if(password.equals(store2))
{
k1=1;
}
}
public static void main(String args[])
{
AtmSystem application=new AtmSystem();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Ⅱ java 編寫ATM提款機程序
原程序的錯誤有:
1.a為int型。去掉『』
2.ATM1 atm = new ATM1 , 類名要和前面的一致
3.加入 a = sc.nextInt();// 請加入此句 進而選擇相應功能,
PS:程序已調好,試試吧。
import java.util.Scanner;
public class ATM1 {
Scanner sc = new Scanner(System.in);
private String name = "lorin";
private double password = 123;
private double money = 500;
public void aloha(){
System.out.println("***********************");
System.out.println("* *");
System.out.println("* 歡迎使用ATM *");
System.out.println("* *");
System.out.println("* 製作人:lorin *");
System.out.println("* *");
System.out.println("* *");
System.out.println("************************");
land();
}
//登陸頁面
public void land(){
System.out.println("請選擇操作界面:1取款,2存款,3查詢,4轉賬,5退出");
int a = sc.nextInt();// 請加入此句
switch(a){
case 1 : // 去掉『』 因為a 為int型。
get();
break;
case 2 :
set();
break;
case 3 :
query();
break;
case 4 :
divert();
break;
case 5 :
SetOut();
break;
}
}
//取款
public void get(){
System.out.println("請輸入取款金額:");
int a = sc.nextInt();
if(a>money){
System.out.println("余額不足!");
}else{
money-=a;
System.out.println("當前余額為:"+money);
land();
}
}
//存款
public void set(){
System.out.println("請輸入存款金額:");
int a = sc.nextInt();
money+=a;
System.out.println("當前余額為:"+money);
land();
}
//查詢
public void query(){
System.out.println("當前余額為:"+money);
land();
}
//轉賬
public void divert(){
System.out.println("該功能站未開放!");
land();
}
//退出
public void SetOut(){
System.exit(0);
}
public static void main(String[] args) {
ATM1 atm = new ATM1();
atm.aloha();
}
}
Ⅲ 如何用Java編寫模擬ATM取款機的程序
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 = 0; i < count; i++) {
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 = 0; i < count2 - 1; i++) {
System.out.print("" + (char) buffer[i]);
}
System.out.println();
// 字元0 ~ 9對應ASCII值48 ~ 57
boolean flag = false;
for (int i = 0; i < count2 - 1; i++) {
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 = 0; i < count2 - 1; i++) {
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 = 0; i < count2 - 1; i++) {
System.out.print("" + (char) buffer[i]);
}
System.out.println();
// 字元0 ~ 9對應ASCII值48 ~ 57
boolean flag = false;
for (int i = 0; i < count2 - 1; i++) {
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 = 0; i < count2 - 1; i++) {
System.out.print("" + (char) buffer[i]);
num += (char) buffer[i];
}
yue += Double.valueOf(num);
System.out.print(",現在余額¥:" + yue);
}
}
}
Ⅳ 用java軟體里的eclipse編ATM取款機(課程設計)
這個嘛,基本上很難
Ⅳ JAVA 「ATM機模擬程序」程序設計課程設計報告
你瘋了,想去買課程設計去專門的網站吧
Ⅵ JAVA課程設計-ATM機模擬系統
可以上網路文庫搜索一下這里有你想要的答案
Ⅶ 設計一個JAVA語言程序關於ATM機 ATM櫃員機模擬程序 功能模塊: 1) 登錄系統
資料庫,多線程,socket,正則表達式,c/s,好好看看著幾塊,你自己就能寫出來了
Ⅷ ATM取款機系統用JAVA怎麼做/
銀行 ATM 客戶
要用到多線程,考慮線程安全
Ⅸ 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();
}
}
}
}