「取款java」取款机
本篇文章给大家谈谈取款java,以及取款机对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
JAVA存取款的数值不准确,要如何改进?
java中的
double在
运算时会有误差,有时候会出现小数点很长的那些数。
在用double值
做运算的时候,你可以先把他们转换为bigDecima类型的后再进行运算
Java编程自动取款机步骤
Java编写的模拟ATM取款机程序/*** @version 1.0
* @author Devil_Angel
* 该程序的功能为实现模拟银行ATM自动取款机提款,查询等功能.
*
*/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;
}
}/**********实现具体取款机功能*********/
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 {
System.out.println("请输入您的信用卡号:");
card=br.readLine();
System.out.println("请输入您的密码:");
pwd=br.readLine();
if(!isRight(card,pwd))
{
System.out.println("您的卡号或密码输入有误.");
counter++;
}
else
SysOpter();
}while(counter3);
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(str.compareTo(str1)0) {
System.out.println("超过已有的钱数,请重新输入您要取的数目:");
}
else {
/*操作成功*/
// act.set_Balance(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.Welcome();
atm.Load_Sys();
// atm.Exit_Sys();
}
} //模拟ATM取款机工作流程 import java.util.Scanner;public class Atm {
public Atm() {
}
public static void main(String[] args) {
// TODO code application logic here
Scanner sc = new Scanner(System.in);
int password = 0;
int count = 0;
int choice = 0;
int type = 0;
int input = 0;
int acount = 1000;
boolean exit = false;
int flag = 0;
do{
System.out.println("请输入您的密码:");
password = sc.nextInt();
count++;
}while(password != 12345 count3);
if(password == 12345){
//密码正确继续后面的操作。
do{
System.out.println("请选择您的操作,1.查询 2.取款");
choice = sc.nextInt();
switch(choice){
case 1:
do{
System.out.println("请选择帐户类型:1. 美元 2. 人民币");
type = sc.nextInt();
if(type == 1){
System.out.println("You have $"+acount+"!");
}else if(type == 2){
System.out.println("您有"+acount+"圆!");
}else{
System.out.println("类型选择错误,请重新选择!");
}
System.out.println("1.继续 2.离开");
flag = sc.nextInt();
if(flag == 1){
exit = false;
}else{
exit = true;
}
}while(type!=1 type!=2);
break;
case 2: do{
System.out.println("请选择帐户类型:1. 美元 2. 人民币");
if(type == 1){
System.out.println("Please input number of your money!");
input = sc.nextInt();
if(input acount){
System.out.println("You have not enough money!");
}else{
System.out.println("You take care of your money!");
}
System.out.println("1.continue 2.exit");
flag = sc.nextInt();
if(flag == 1){
exit = false;
}else{
exit = true;
}
}else if(type == 2){
System.out.println("请输入您要取的金额!");
input = sc.nextInt();
if(input acount){
System.out.println("您的余额不足!");
}else{
System.out.println("请妥善保管您的钱!");
acount = acount - input;
}
System.out.println("1.继续 2.离开");
flag = sc.nextInt();
if(flag == 1){
exit = false;
}else{
exit = true;
}
}else{
System.out.println("类型选择错误,请重新选择!");
}
}while(type!=1 type!=2);
break;
default: System.out.println("类型选择错误,请重新选择!");
}
}while(choice!=1 choice!=2 || exit == false);
}else{
//密码错误,退出。
System.out.println("三次密码错误,吞卡!");
}
}
}
如何用Java线程实现银行的存款取款问题最好能写出编出的具体程序
AccountTest.java class BankAccount //定义银行账户类BankAccount{private static int amount =2000; //账户余额最初为2000public void despoit(int m) //定义存款的方法{amount=amount+m;System.out.println("晓明存入["+m+"元]");}public void withdraw(int m) //定义取款的方法{amount=amount-m;System.out.println("张新取走["+m+"元]");if(amount0)System.out.println("***余额不足!***);public int balance() //定义得到账户余额的方法{return amount;}}classicCustomerextendsThread {String name;BankAccount bs; //定义一个具体的账户对象public Customer(BankAccount b,String s){name=s;bs=b;}public static void cus(String name,BankAccount bs) //具体的账户操作方法{if(name.equals("小明")) //判断用户是不是小明{try{for(int i=0;i6;i++) //用户晓明则向银行存款6次,每次1000元 {Thread.currentThread().sleep((int)(Math.random()*300));bs.despoit(1000);}}catch(InterruptedException e){}}else{try{for(int i=0;i6;i++) //用户不是小明则从银行取款6次,每次1000元{Thread.currentThread().sleep((int)(Math.random()*300));bs.withdraw(1000); }}catch(InterruptedException e){} }}public void run() //定义run方法}cus(name,bs); }}public classAccountTest{public static void main(String [] args) throws InterruptedException{BankAccount bs=new BankAccount();Customer customer1=new Customer(bs,"小明");Customer customer2=new Customer(bs,"张新");Thread t1=new Thread(customer1);Thread t2=new Thread(customer2);t1.Start();t2.start();Thread.currentThread().sleep(500);}}
取款java的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于取款机、取款java的信息别忘了在本站进行查找喔。
发布于:2022-11-24,除非注明,否则均为
原创文章,转载请注明出处。