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!=nullpassword!=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();
}
}
}
}
import javax.swing.JOptionPane;
public class Account
{
private String name;
private String account;
private String data;
private String ID;
private double balance;
public Account(String name,double balance,String data,String ID)
{
this.name = name;
this.balance = balance;
this.data=data;
this.ID=ID;
}
public String getaccount()
{
this.account=String.valueOf((int)(Math.random()*100000)+1);
return account;
}
public String getdata()
{
return data;
}
public String getID()
{
return ID;
}
public String getName()
{
return name;
}
public double getbalance()
{
return balance;
}
//查看账户余额
public double balance()
{
return balance;
}
//查看开户时间
public String data()
{
return data;
}
//存款操作
public boolean put(double value)
{
if (value0)
{
this.balance += value;
return true;
}
return false;
}
//取款操作
public double get(double value)
{
if (value0)
{
if (value=this.balance)
this.balance -= value;
else
{
value = this.balance;
this.balance = 0;
}
return value;
}
return 0;
}
public static void main(String args[]){
Account user=new Account("张三",2000,"2011/05/23","362329198906234225");
String str;
int b;
String s=JOptionPane.showInputDialog("您好,存款选择1,取款选择2,退出选择0");
int x=Integer.parseInt(s);
while(x!=0){
if(x==1)
{
str=JOptionPane.showInputDialog("输入您要存入的数额");
b=Integer.parseInt(str);
if( user.put(b)){
JOptionPane.showMessageDialog(null, "请放入钞票!");
JOptionPane.showMessageDialog(null,"开户账号为"+user.getaccount()+"\n"+user.getName()+"\n开户时间为"+user.data()+"\n您的余额为"+user.balance());
}
else
JOptionPane.showMessageDialog(null, "你所输入的存款数额有误!");
}
else{
str=JOptionPane.showInputDialog("输入您要取出的数额");
b=Integer.parseInt(str);
if(buser.balance())
{
JOptionPane.showMessageDialog(null, "余额不足");
}
else
{
JOptionPane.showMessageDialog(null, "请取出钞票!");
user.get(b);
JOptionPane.showMessageDialog(null,"开户账号为"+user.getaccount()+"\n"+user.getName()+"\n开户时间为"+user.data()+"\n您的余额为"+user.balance());
}
}
s=JOptionPane.showInputDialog("您好,存款选择1,取款选择2,退出选择0");
x=Integer.parseInt(s);
}
}
}
public static void main(String[] args) {
String realPwd = "111111";
Integer errorCount = 0;
Integer account;
Scanner sc = new Scanner(System.in);
while(true){
System.out.print("请输入密码:");
String pwd = sc.next();
if(!pwd.equals(realPwd)){
errorCount++;
System.out.println("第"+errorCount+"次输入密码不正确");
if(errorCount=3){
System.out.println("密码错误,请取卡");
break;
}
}else{
while(true){
System.out.print("请输入取款金额:");
account = sc.nextInt();
if(account1000 || account0){
System.out.println("取款金额最低0元,最高1000元");
}else if(account%100!=0){
System.out.println("只有100的纸币");
}else{
System.out.println("取款金额"+account+"元");
System.out.println("交易完成,请取卡");
break;
}
}
break;
}
}
}
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;
}
}
}
}
代码如下
package BaiDdu;
import java.util.Scanner;
public class ATM {
/*1提示请输入密码然后直接进入下一步。密码6位限制(限制方法用 “最小大于100000最大小于999999”这样限制)
2.提示密码正确还是错误密码直接弄成“123456”错误返回上一步循环方法用for循环。
3.密码输入正确后进入下一步提示5个选项(1.余额查询“基础10000”2.取款 3存款4.退出)
4.进行取款或者存款之后要回到第三步重新选择(余额和取款存款相关联)
备注:用键盘输入的方法用scanner*/
private static int money=10000;//全局变量 余额 默认10000
public static void main(String args[])
{
for(;;){//for循环,有意思吗?
System.out.println("请输入密码:");
Scanner input=new Scanner(System.in);
int pw=input.nextInt();
if ( Checkpw(pw)) {
System.out.println("密码正确。");
Next();
}
else System.out.println("密码错误!");
}
}
public static boolean Checkpw(int pw)
{
if (pw==123456)return true;//固定密码就不需要限制位数了,反正不符合就错
else
return false;
}
public static void Next() {
do {
System.out.println("请选择你需要的功能:");
System.out.println("1.余额查询 2.取款 3.存款 4.退出");
int value = new Scanner(System.in).nextInt();
switch (value) {
case 1:// 查询余额
System.out.println("您的余额为 "+money+"元");
break;
case 2:// 取款
System.out.println("请输入取款金额:");
int getnum=new Scanner(System.in).nextInt();
if (getnum0) System.out.println("输入金额有误!");
else if(getnummoney)System.out.println("余额不足.");
else {money=money-getnum;System.out.println("取款成功,余额为"+money);}
break;
case 3:// 存款
System.out.println("请输入存款金额:");
int pushnum= new Scanner(System.in).nextInt();
if (pushnum0) System.out.println("输入金额有误!");
else {money=money+pushnum;System.out.println("存款成功,余额为"+money);}
break;
case 4:// 退出
System.out.println("谢谢使用!");
System.exit(0);
break;
default:
System.out.println("输入有误");
break;
}
}while(true);
}
}
2、运行效果
/** * @author admin * 该程序的功能为实现模拟银行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(); } 回复获取全部
售后响应及时
7×24小时客服热线数据备份
更安全、更高效、更稳定价格公道精准
项目经理精准报价不弄虚作假合作无风险
重合同讲信誉,无效全额退款