| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2617 人关注过本帖
标题:[求助]关于用Java实现ATM机的挠头难题,大家会么?
只看楼主 加入收藏
JasonSong
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2006-6-4
收藏
 问题点数:0 回复次数:2 
[求助]关于用Java实现ATM机的挠头难题,大家会么?
Java论坛没人,只好老这里了
大家好!最近我在编个ATM机GUI程序,用swing做,可是现在遇到4个错误了,但我一直不知道怎么解决。
我的主程序AtmGUI程序如下, 现在总是提示红色字的地方有问题,“cannot resolve symbol : constructor KeyPad (AtmGUI)”和“cannot resolve symbol : constructor KeyPad (AtmGUI)”
万能的搂住能不能指点一下?苦恼死了

import javax.swing.*; //Packages used
import java.awt.*;
import java.awt.event.*;

public class AtmGUI extends JFrame
implements ActionListener{

private JButton confirm = new JButton("Confirm");
private JTextField input = new JTextField(20);
private JTextArea display = new JTextArea(5,20);
private KeyPad keypad = new KeyPad(this);
private FounctionPad founctionpad = new FounctionPad(this);


public AtmGUI(){

getContentPane().setLayout(new BorderLayout());
keypad = new KeyPad(this);
founctionpad = new FounctionPad(this);

getContentPane().add(input,"North"); //input

getContentPane().add(display,"Center"); //display
display.setLineWrap(true);
display.setEditable(false);

JPanel controlPanel = new JPanel(new BorderLayout(0,0)); //control panel
controlPanel.add(keypad,"Center");
controlPanel.add(confirm,"South");
getContentPane().add(controlPanel,"East");

getContentPane().add(founctionpad,"West"); //founction

confirm.addActionListener(this);
input.addActionListener(this);
}

public void actionPerformed(ActionEvent e){
double cash = Double.valueOf(input.getText()).doubleValue();
display.append(cash+"\n");
input.setText("");
}



public void keypressCallback(String s){
if(s.equals("C"))
input.setText("");
else
input.setText(input.getText() + s);
}

public static void main(String args[]){
AtmGUI f = new AtmGUI();
f.setSize(400,300);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

}
搜索更多相关主题的帖子: ATM Java 难题 挠头 
2006-06-04 15:13
enenaiai123
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-11-1
收藏
得分:0 
正确答案,刚做的
package com.kay.bank;

import java.util.Scanner;

public class Bank {

    Scanner input = new Scanner(System.in);
    Data data = new Data();
    User crUser; //当前登陆的用户
    
    public void start()
    {
        System.out.println("--------------------");
        System.out.println("1.开户");
        System.out.println("2.插卡");
        System.out.println("3.系统管理");
        System.out.println("4.退出");
        System.out.println("--------------------");
        System.out.println("请选择菜单:");
        int num = input.nextInt();
        switch(num)
        {
        case 1:
            //开户操作
            openAccount();
            break;
        case 2:
            //插卡操作
            insertCard();
            break;
        case 3:
            //x系统管理操作
            systemManager();
            break;
        default:
            //退出
        }
    }
    /**
     * 开户
     */
    public void openAccount()
    {
        User user = new User();
        System.out.println("****************");
        System.out.println("请输入用户名:");
        user.name = input.next();
        //验证系统中用户名是否存在
        User checkUser = data.checkUserByName(user.name);
        if(checkUser == null)
        {
            //系统中用户名不存在
        
            System.out.println("请输入密码:");
            String pwd = input.next();
            System.out.println("请确认密码:");
            String repwd = input.next();
            
            if(pwd.equals(repwd))
            {
                user.pwd = pwd;
                System.out.println("请输入存款金额:");
                double money = input.nextDouble();
                if(money <= 0)
                {
                    System.out.println("输入的金额不合法,请重新输入!");
                    openAccount();
                }
                else
                {
                    user.money = money;
                    //向数据库中存放新创建的User
                    data.saveUser(user);
                    
                    System.out.println("创建新用户成功!");
                    start();
                }
            }
            else
            {
                System.out.println("密码不一致,请重新输入!");
                openAccount();
            }
        }
        else
        {
            System.out.println("用户名已存在");
            start();
        }
    }
    /**
     * 插卡操作
     */
    public void insertCard()
    {
        System.out.println("请输入用户名:");
        String name = input.next();
        System.out.println("请输入密码:");
        String pwd = input.next();
        
        
            User user = data.checkUser(name, pwd);
            if(user != null)
            {
                if(user.isEnable == true)
                {
                    System.out.println("登陆成功");
                    crUser = user;
                    showCustomMenu();
                }
                else
                {
                    System.out.println("您的账户被冻结,请打110");
                    start();
                }
            }
            else
            {
                System.out.println("用户名或密码错误");
                insertCard();
            }
        
        
    }
    /**
     * 显示插卡登陆成功后二级菜单
     */
    public void showCustomMenu()
    {
        System.out.println("---------------");
        System.out.println("1.查询余额");
        System.out.println("2.取款");
        System.out.println("3.存款");
        System.out.println("4.转账");
        System.out.println("5.修改密码");
        System.out.println("6.退出");
        System.out.println("---------------");
        System.out.println("请选择:");
        int num = input.nextInt();
        switch(num)
        {
        case 1:
            //查询余额
            getMoney();
            break;
        case 2:
            //取款
            minusMoney();
            break;
        case 3:
            //存款
            addMoney();
            break;
        case 4:
            //转账
            transitionMoney();
            break;
        case 5:
            //修改密码
            updatePwd();
            break;
        case 6:
            exitCustomMenu();
            //退出
        }    
    }
    /**
     * 获得当前用户的余额
     */
    public void getMoney()
    {
        System.out.println("您的余额为:" + crUser.money);
        showCustomMenu();
    }
    /**
     * 取款
     */
    public void minusMoney()
    {
        System.out.println("请输入取款额:");
        double money = input.nextDouble();
        if(money >= 0 && money < crUser.money)
        {
            //可以取款
            crUser.money = crUser.money - money;
            showCustomMenu();
        }
        else
        {
            System.out.println("金额有误!请重新输入!");
            minusMoney();
        }
    }
    
    public void exitCustomMenu()
    {
        start();
    }
    /**
     * 存款
     */
    public void addMoney()
    {
        System.out.println("请输入存款额:");
        double money = input.nextDouble();
        if(money >= 0)
        {
            crUser.money = crUser.money + money;
            showCustomMenu();
        }
        else
        {
            System.out.println("金额不合法!");
            addMoney();
        }
    }
    /**
     * 修改密码
     */
    public void updatePwd()
    {
        System.out.println("请输入原始密码:");
        String oldPwd = input.next();
        if(oldPwd.equals(crUser.pwd))
        {
            System.out.println("请输入新密码:");
            crUser.pwd = input.next();
            showCustomMenu();
        }
        else
        {
            System.out.println("原始错误,请重新输入!");
            updatePwd();
        }
    }
    /**
     * 转账
     */
    public void transitionMoney()
    {
        System.out.println("请输入要转入的账号名称:");
        String name = input.next();
        User intoUser = data.checkUserByName(name);
        
        if(intoUser != null)
        {
            //转入的账号存在
            System.out.println("请输入转入的金额:");
            double money = input.nextDouble();
            if(money >= 0 && money < crUser.money)
            {
                //金额合法并且余额满足转账条件 可以进行转账
                crUser.money = crUser.money - money;
                intoUser.money = intoUser.money + money;
                showCustomMenu();
            }
            else
            {
                System.out.println("金额不合法,请重新输入!");
                transitionMoney();
            }
        }
        else
        {
            System.out.println("转入的账号不存在,请重新输入!");
            transitionMoney();
        }
    }
    /**
     * 系统管理
     */
    public void systemManager()
    {
        System.out.println("请输入管理员密码:");
        String pwd = input.next();
        if(pwd.equals("admin"))
        {
            //管理员登陆成功
            showManagerMenu();
        }
        else
        {
            System.out.println("密码错误!");
            start();
        }
    }
    /**
     * 显示管理员登陆后的菜单
     */
    public void showManagerMenu()
    {
        System.out.println("******************");
        System.out.println("1.显示所有用户");
        System.out.println("2.冻结账号");
        System.out.println("3.恢复账号");
        System.out.println("4.退出");
        System.out.println("******************");
        System.out.println("请选择菜单项:");
        int num = input.nextInt();
        switch(num)
        {
        case 1:
            //显示所有用户
            showAllUser();
            break;
        case 2:
            //冻结账号
            freezeAccount();
            break;
        case 3:
            //恢复账户
            renewAccount();
            break;
        case 4:
            start();
            //退出
        }
    }
    /**
     * 显示所有用户
     */
    public void showAllUser()
    {
        System.out.println("系统中所有用户:");
        System.out.println("--------------------------------");
        System.out.println("用户名\t是否可用");
        for (int i = 0; i < data.userArray.length; i++) {
            User user = data.userArray[i];
            if(user != null)
            {
                System.out.println(user.name + "\t" + user.isEnable);
            }
        }
        System.out.println("--------------------------------");
        showManagerMenu();
    }
    /**
     * 冻结账户
     */
    public void freezeAccount()
    {
        System.out.println("系统中所有可被冻结用户:");
        System.out.println("--------------------------------");
        System.out.println("用户名\t是否可用");
        for (int i = 0; i < data.userArray.length; i++) {
            User user = data.userArray[i];
            if(user != null && user.isEnable == true)
            {
                System.out.println(user.name + "\t" + user.isEnable);
            }
        }
        System.out.println("--------------------------------");
        System.out.println("请输入要被冻结的账户:");
        String name = input.next();
        User user = data.checkUserByName(name);
        if(user != null)
        {
            //要冻结的账户存在
            user.isEnable = false;
            System.out.println("冻结成功!");
            
        }
        else
        {
            System.out.println("用户不存在!");
        }
        showManagerMenu();
    }
    /**
     * 恢复账户
     */
    public void renewAccount()
    {
        System.out.println("系统中所有可被恢复用户:");
        System.out.println("--------------------------------");
        System.out.println("用户名\t是否可用");
        for (int i = 0; i < data.userArray.length; i++) {
            User user = data.userArray[i];
            if(user != null && user.isEnable == false)
            {
                System.out.println(user.name + "\t" + user.isEnable);
            }
        }
        System.out.println("--------------------------------");
        System.out.println("请输入要被恢复的账户:");
        String name = input.next();
        User user = data.checkUserByName(name);
        if(user != null)
        {
            //要恢复的账户存在
            user.isEnable = true;
            System.out.println("恢复成功!");
            
        }
        else
        {
            System.out.println("用户不存在!");
        }
        showManagerMenu();
    }
    
    
    
    
    
    
    
    
    
}





package com.kay.bank;

public class Data {

    User[] userArray = new User[100];
    
    /**
     * 存储新的用户
     * @param user 新用户对象
     */
    public void saveUser(User user)
    {
        for (int i = 0; i < userArray.length; i++) {
            if(userArray[i] == null)
            {
                userArray[i] = user;
                break;
            }
            
        }
    }
    /**
     * 根据用户名和密码验证用户是否在数组中存在
     * @param name 用户名
     * @param pwd 密码
     */
    public User checkUser(String name,String pwd)
    {
        for (int i = 0; i < userArray.length; i++) {
            User user = userArray[i];
            if(user != null
                    && user.name.equals(name)
                    && user.pwd.equals(pwd))
            {
                //代表用户存在
                return user;
            }
        }
        return null;
    }
    /**
     * 根据用户名验证用户是否存在
     * @param name
     * @return
     */
    public User checkUserByName(String name)
    {
        for (int i = 0; i < userArray.length; i++) {
            User user = userArray[i];
            if(user != null
                    && user.name.equals(name))
            {
                //代表用户存在
                return user;
            }
        }
        return null;
    }
}



package com.kay.bank;

public class Test {

    public static void main(String[] args) {
        Bank atm = new Bank();
        atm.start();
    }
}



package com.kay.bank;

public class User {

    String name;
    String pwd;
    double money;
    boolean isEnable = true;
}
2008-11-01 22:11
cfm1989
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2008-11-12
收藏
得分:0 
顶啊~~~~~~~~~~好东西,刚学java
收下了.昨天刚学着编了下面这个,看来可以加东西进去啦
/**
 * @version 1.0
 * @author Devil_Angel
 * 该程序的功能为实现模拟银行ATM自动取款机提款,查询等功能.
 *
 */

import *;

/*该类为实现客户信息及部分功能*/
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)
 
 
 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;
 }
}

/**********实现具体取款机功能*********/
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");
 }


/**********登陆系统**********/
 protected void Load_Sys() throws Exception
 {
  String card,pwd;
  int counter=0;
  
  BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  do
   else
    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-4):");
  num=br.read();  //num为ASICC码转换的整数
  switch(num) {
  case 49: BetBalance(); break;
  case 50: Inqu_Info(); break;
  case 51: Set_Password(); break;
  case 52: Exit_Sys();  break;
  }
  System.exit(1);
 }
 
 /**********信息查询**********/
 protected void Inqu_Info() {
  System.out.print("---------------------n"+
       act.get_Code()+"n"+
       act.get_Name()+"n"+
       act.get_Money()+"n"+
       "-----------------------");
 }

/**********取款**********/
 public void BetBalance() throws Exception
 {
  String str=null,str1;
  BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  do {
   System.out.println("请输入您要取的数目:");
   str=br.readLine();
   str1=String.valueOf(act.get_Money());
   if((str1)>0)
   else
  }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))
     
     else
     
    }while(true);
   }
  }while(counter>3);
  
 }
 
 /**********锁定机器**********/
 protected void Lock_Sys()
 
 /**********结束系统**********/
 protected void Exit_Sys()
 
}

public class Text
{
 public static void main(String[] args) throws Exception
 {
  ATM atm=new ATM();
  atm.Welcome();
  atm.Load_Sys();
//  atm.Exit_Sys();
 }
}
2009-08-03 14:49
快速回复:[求助]关于用Java实现ATM机的挠头难题,大家会么?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.050166 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved