新网创想网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

javaatm代码 javaatm机

求Java代码 模拟简易atm机

参考了别人的代码。略作修改,已经很简单了:

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:国际域名空间、网页空间、营销软件、网站建设、长春网站维护、网站推广。

InfoATM.java:

public class InfoATM {

double money = 0;

public InfoATM(double cash) {

super();

this.money = cash;

}

// 存款的方法

public void save(double count) {

money += count;

}

// 取款的方法

public void draw(double count) {

money -= count;

}

public double getMoney() {

return money;

}

public void setMoney(double money) {

this.money = money;

}

}

TestATM.java:

import java.awt.BorderLayout;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JTextField;

public class TestATM extends JFrame {

private static final long serialVersionUID = 2531222181184935595L;

// 主面板pnBasic是用来装pnDate和标签文字的。

private JPanel pnBasic;

// 添加到主面板中的中间 pnDate面板是为了装表单的。

private JPanel pnDate;

// 添加到主面板中的北边 pnLabel面板是为了装欢迎词的

private JPanel pnLabel;

InfoATM atm = new InfoATM(0);

public TestATM() {

pnBasic = new JPanel();

// 主面板pnBasic是用来装pnDate和标签文字的。

pnDate = new JPanel(new GridLayout(2, 2));

// pnDate面板是为了装表单的。

pnLabel = new JPanel();

JLabel top = new JLabel("欢迎来到中国银行!");

pnLabel.add(top);

// 先将数值添加在一个容器中并设置其在容器的右边,在将容器添加在网格的第一格

JPanel jp1 = new JPanel();

JLabel number = new JLabel("数值:");

final JTextField box = new JTextField(5);

jp1.add(number);

jp1.add(box);

JPanel jp2 = new JPanel();

JButton create = new JButton("新建银行账户");

jp2.add(create);

JButton take = new JButton("取款");

JButton in = new JButton("存款");

pnDate.add(jp1);

pnDate.add(jp2);

pnDate.add(take);

pnDate.add(in);

// 加一句下面的就好了

JPanel jpS = new JPanel();

final JLabel total = new JLabel("您现在的账户余额是:0 元");

jpS.add(total);

pnBasic.setLayout(new BorderLayout());

pnBasic.add(pnLabel, BorderLayout.NORTH);

pnBasic.add(pnDate, BorderLayout.CENTER);

pnBasic.add(jpS, BorderLayout.SOUTH);

setContentPane(pnBasic);

setBounds(400, 250, 500, 500);

pack();

setDefaultCloseOperation(DISPOSE_ON_CLOSE);

setVisible(true);

pack();

in.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

if (box.getText() != null  box.getText() != "") {

try {

double count = Double.parseDouble(box.getText());

if (count  0) {

atm.save(count);

total.setText("您现在的账户余额是:" + atm.getMoney() + "元");

box.setText("");

}

} catch (Exception e1) {

System.out.println("您输入的数值必须是数字");

}

}

}

});

take.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

if (box.getText() != null  box.getText() != "") {

try {

double count = Double.parseDouble(box.getText());

if (count = 0  count = atm.getMoney()) {

atm.draw(count);

total.setText("您现在的账户余额是:" + atm.getMoney() + "元");

box.setText("");

} else {

System.out.println("你的余额不足,取款失败");

}

} catch (Exception e1) {

System.out.println("您输入的数值必须是数字");

}

}

}

});

create.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

total.setText("您现在的账户余额是:0元");

atm.setMoney(0);

box.setText("");

}

});

}

public static void main(String[] args) {

new TestATM();

}

}

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;

}

}

}

}

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("卡片已经被锁,请联系客服人员!");

}

}

回答不易望请采纳

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(counter3);

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(counter3);

}

/**********锁定机器**********/

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金额。简单版本的存取款。


分享文章:javaatm代码 javaatm机
本文地址:http://www.wjwzjz.com/article/hgdjip.html
在线咨询
服务热线
服务热线:028-86922220
TOP