Account.java

/*

信1705-3 20173612  陈阳阳

*/
package ATM;

public class Account {
 private String accountID;//用户的账号
 
 private String accountname;//账户的名称
 
 private String operatedate;//操作的日期
 
 private int operatetype;//操作的类型
 
 private String accountpassword;//用户的密码
 
 private int accountbalance;//账户的余额
 
 private int amount;//操作流水的金额
 public Account(String accountID, String accountname, String operatedate, int operatetype,

String accountpassword,int accountbalance,int amount) {

this.accountID = accountID;

this.accountname = accountname;

this.operatedate = operatedate;

this.operatetype = operatetype;

this.accountpassword = accountpassword;
  
  this.accountbalance = accountbalance;
  
  this.amount = amount;}
 
 public String getAccountID() {
  return accountID;
 }
 public void setAccountID(String accountID) {
  this.accountID = accountID;
 }

public String getAccountName() {
  return accountname;
 }
 public void setAccountName (String accountName) {
  this.accountname = accountName;
 }
 
 public String getOperatedate() {
  return operatedate;
 }
 public void setOperatedate(String Operatedate) {
  this.operatedate = Operatedate;
 }
 
 public int getOperatetype() {
  return operatetype;
 }
 public void setOperatetype(int Operatetype) {
  this.operatetype = Operatetype;
 }
 
 public String getAccountpassword() {
  return accountpassword;
 }
 public void setAccountpassword(String accountpassword) {
  this.accountpassword = accountpassword;
 }
 
 public int getAccountbalance() {
  return accountbalance;
 }
 public void setAccountbalance(int accountbalance) {
  this.accountbalance = accountbalance;
 }
 
 public int getAmount() {
  return amount;
 }
 public void setAmount(int amount) {
  this.amount = amount;
 }
}

AccountManager.java

package ATMOP;
import java.util.*;
public class AccountManager {
 @SuppressWarnings({ "resource", "unused" })//(“unused”)未使用的变量  (“resource”)有泛型未指定类型
 public static void main(String[] args)  throws NumberErrorException {
  // TODO Auto-generated method stub
  Scanner in=new Scanner(System.in);
        PATM atm=new ATM();
        NumberErrorException nee=new NumberErrorException("输入非法!");
        NotHundredTimesException nhte=new NotHundredTimesException("不是一百的整数倍!");
        PasswordErrorException pee=new PasswordErrorException("输入错误的密码超过三次!");
        int passwordErrorTimes=0;
        int choose=-1,number=0,x=0;
        String num="";
        String pw="";
        next:while(true){
         System.out.println("******************************");
            System.out.println("   欢迎使用中国工商银行自助柜员系统       ");
            System.out.println("******************************");
            System.out.println("请输入您的账号:");
            int kk=-1;
            String c=in.next();
            if(whetherNum(c))
                kk=Integer.parseInt(c);
            if(kk==0) break;
            else if(kk!=1){
                System.out.println("输入错误!");
                continue;
            }
            System.out.println("************************************************");
            System.out.println("  欢迎***使用中国工商银行自助柜员系统  ");
            System.out.println("************************************************");
            System.out.println("请输入您的密码:");
            pw=in.next();
            if(atm.ifPass(pw)){
                while(true){
                    showFace();
                    String cc=in.next();
                    if(whetherNum(cc))
                        choose=Integer.parseInt(cc);
                    switch(choose){
                    case 1:
                     System.out.println("******************************************");
                        System.out.println("  欢迎***使用中国工商银行自助柜员系统  ");
                        System.out.println("*******************************************");
                        System.out.println("输入存款金额:");
                        while(true){
                            try{
                                num=in.next();
                                if(!whetherNum(num))
                                    throw nee;
                                else if((x=Integer.parseInt(num)%100)!=0)
                                    throw nhte;
                                else
                                    break;
                            }
                            catch(NumberErrorException e){
                                System.out.println("输入正确的数字!");
                            }
                            catch(NotHundredTimesException e){
                                System.out.println("录入错误,请输入合法的整数(100的整数倍)!");
                            }
                        }
                        number=Integer.parseInt(num);
                        atm.save(number);
                        System.out.println("****************************************************");
                        System.out.println("  欢迎***使用中国工商银行自助柜员系统  ");
                        System.out.println("****************************************************");
                        System.out.println("当前账户存款操作成功。");
                        System.out.println("当前账户余额为:"+atm.getRest()+"元");
                        break;
                    case 2:
                     System.out.println("*****************************************************");
                     System.out.println("  欢迎***使用中国工商银行自助柜员系统  ");
                        System.out.println("*****************************************************");
                        System.out.println("当前用户每日可以支取2万元。");
                        System.out.println("请选择:");
                        int a[]={100,500,1000,1500,2000,5000};
                        for(int i=0;i<a.length;i++)
                            System.out.println((i+1)+"."+a[i]+"元");
                        System.out.println("7.其他金额");
                        String bb="";
                        int ch=-1;
                        bb=in.next();
                        if(whetherNum(bb)){
                            ch=Integer.parseInt(bb);
                        }
                        if(ch>=1&&ch<=6){
                            if(atm.withdraw(a[ch-1]))
                            {
                            System.out.println("*************************************************");
                            System.out.println("  欢迎***使用中国工商银行自助柜员系统  ");
                            System.out.println("*************************************************");
                            System.out.println("当前账户取款操作成功!     ");
                            }
                            else
                                System.out.println("账户余额不足!");
                        }
                        else if(ch==7){
                         System.out.println("*****************************************************");
                            System.out.println("  欢迎***使用中国工商银行自助柜员系统  ");
                            System.out.println("***************************************************");
                            System.out.println("请输入取款金额:");
                            while(true){
                                try{
                                    num=in.next();
                                    if(!whetherNum(num))
                                        throw nee;
                                    else if((x=Integer.parseInt(num)%100)!=0)
                                        throw nhte;
                                    else
                                        break;
                                }
                                catch(NumberErrorException e){
                                    System.out.println("输入正确的数字!");
                                }
                                catch(NotHundredTimesException e){
                                    System.out.println("录入错误,请输入合法的整数(100的整数倍)!");
                                }
                            }
                            number=Integer.parseInt(num);
                            if(atm.withdraw(number))
                                System.out.println("取款成功!");
                            else
                                System.out.println("余额不足!");
                        }
                        else
                            System.out.println("输入有误!");
                        System.out.println("当前余额:"+atm.getRest()+"元");
                        break;
                    case 3:
                     System.out.println("******************************************************");
                        System.out.println("  欢迎***使用中国工商银行自助柜员系统  ");
                        System.out.println("*******************************************************");
                        System.out.println("请输入转账账户:");
                        String s=in.next();
                        System.out.println("***************************************************");
                        System.out.println("  欢迎***使用中国工商银行自助柜员系统  ");
                        System.out.println("***************************************************");
                        System.out.println("请输入转账金额:");
                        while(true){
                            try{
                                num=in.next();
                                if(!whetherNum(num))
                                    throw nee;
                                else if((x=Integer.parseInt(num)%100)!=0)
                                    throw nhte;
                                else
                                    break;
                            }
                            catch(NumberErrorException e){
                                System.out.println("输入正确的数字!");
                            }
                            catch(NotHundredTimesException e){
                                System.out.println("录入错误,请输入合法的整数(100的整数倍)!");
                            }
                        }
                        number=Integer.parseInt(num);
                        if(atm.transfer(s, number))
                            System.out.println("转账成功!");
                        else
                            System.out.println("转账失败!");
                        System.out.println("当前余额:"+atm.getRest()+"元");
                        break;
                    case 4:
                     System.out.println("输入当前密码:");
                     String M=in.next();
                        System.out.println("输入修改密码:");
                        String p=in.next();
                        if(p.length()==6&&whetherNum(p))
                            atm.setPassword(p);
                        else{
                            System.out.println("不是六位或者不是数字!");
                        }
                        break;
                    case 5:
                        System.out.println("当前余额:"+atm.getRest()+"元");
                        break;
                    default:
                        continue next;
                    }
                }
            }
            else{
                System.out.println("密码错误!");
                try{
                    passwordErrorTimes++;
                    if(passwordErrorTimes>3)
                        throw pee;
                }
                catch(PasswordErrorException e){
                    System.out.println(e.getMessage()+"账户暂时冻结!");
                    return ;
                }
            }

}
 }
  //显示菜单
    public static void showFace(){
     System.out.println("**********************************************************");
        System.out.println("  欢迎***使用中国工商银行自助柜员系统  ");
        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("请选择:");
    }
    //判断字符串是否为整数(0-999999)
    public static boolean whetherNum(String s){
        boolean flag=true;
        if(s.length()>=7)
            return false;
        char arr[]=s.toCharArray();
        for(int i=0;i<s.length();i++){   
            if(arr[i]<'0'||arr[i]>'9')
                flag=false;
        }
        return flag;
    }
}

class PersonalAccount{
    private String passWord="123456";//密码
    @SuppressWarnings("unused")
    private String number;//银行卡号
    private int money=0;
    public int getMoney(){return money;}//余额
    public void setPw(String s){passWord=s;}//设置密码
    public void addMoney(int x){money+=x;}//加钱
    public void minusMoney(int x){money-=x;}//减钱
    public boolean whetherPwTrue(String s){//密码是否正确
        if(s.equals(passWord))
            return true;
        else return false;
    }
}
//abstract修饰类,会使这个类成为一个抽象类
abstract class PATM{
    public abstract boolean withdraw(int x);//取款
    public abstract void save(int x);//存款
    public abstract boolean transfer(String s,int x);//转账
    public abstract boolean ifPass(String s);//判断输入的密码是否正确
    public abstract int getRest();//查询余额
    public abstract void setPassword(String s);//设置密码
}
class ATM extends PATM{
    private String numbers[]={"1234567891000000","11112222333344445"};//已有的账户卡号
    private PersonalAccount account=new PersonalAccount();
    public boolean withdraw(int x) {
        if(x>account.getMoney())
            return false;
        else{
            account.minusMoney(x);
            return true;
        }
    }
    public void save(int x) {
        account.addMoney(x);
    }
    public boolean transfer(String s, int x) {
        //转账
        //先判断转到账户号是否存在
        //再判断余额是否足够
        boolean flag=false;
        for(int i=0;i<numbers.length;i++)//比较s是否和t相等,返回一个boolean类型的值(即false或者true)
            if(s.equals(numbers[i])) flag=true;//equals()方法在Object定义中是与==相等.就是比较2个对象引用是否相等
        if(x>account.getMoney()) flag=false;
        if(x<=account.getMoney()&&flag) account.minusMoney(x);;
        return flag;
    }
    public boolean ifPass(String s) {
        return account.whetherPwTrue(s);
    }
    public int getRest() {
        return account.getMoney();
    }
    public void setPassword(String s) {
        account.setPw(s);       
    }
}
@SuppressWarnings("serial")
class NumberErrorException extends Exception{
    public NumberErrorException(String msg){
        super(msg);
    }
}
@SuppressWarnings("serial")
class PasswordErrorException extends Exception{
    public PasswordErrorException(String msg){
        super(msg);
    }
}
@SuppressWarnings("serial")
class NotHundredTimesException extends Exception{
    public NotHundredTimesException(String msg){
        super(msg);
    }
}

java开学第一周测试代码的更多相关文章

  1. java开学第一周测试自我感想

    开学第一周,王建民老师就对我们进行了java测试,对我们说测试题目是基于期末考试的基础难度来出的.我们的考试完全是靠暑假在家自学的基础,如果在家没有自学java,那完全就是看不懂试卷到底要考什么.由于 ...

  2. 201871010106-丁宣元 《面向对象程序设计(java)》第一周学习总结

    丁宣元 <面向对象程序设计(java)>第一周学习总结 正文开头 项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在 ...

  3. 201521044152<java程序设计>第一周学习总结

    本周学习总结 java开发时间虽然很短,但是发展迅速,已成为现在非常流行的一门语言,很开心能有幸学习java.第一周学习了java的平台,运行环境jdk以及jrt等等新名词,还了解了eclipse的基 ...

  4. 201671010140. 2016-2017-2 《Java程序设计》java学习第一周

       java学习第一周        本周是新学期的开端,也是新的学习进程的开端,第一次接触java这门课程,首先书本的厚度就给我一种无形的压力,这注定了,这门课程不会是轻松的,同时一种全新的学习方 ...

  5. 20145304 刘钦令 Java程序设计第一周学习总结

    20145304<Java程序设计>第1周学习总结 教材学习内容总结 1995年5月23日,是公认的Java的诞生日,Java正式由Oak改名为Java. Java的三大平台是:Java ...

  6. 扎西平措 201571030332《面向对象程序设计 Java 》第一周学习总结

    <面向对象程序设计(java)>第一周学习总结 正文开头: 项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 ...

  7. 20165213 java学习第一周

    20165213 -2018-2<Java程序设计>第一周学习总结 教材学习内容总结 java的四个特点:面向对象.平台无关性.动态性.简单. java编写程序步骤:再有jdk的情况下,先 ...

  8. Java学习第一周博客

    20145307<Java程序设计>第一周学习总结 教材学习内容总结 首先学习安装Java有两种方法,一种是用Eclipse直接编辑输出,另一种方法是用记事本之后用win+G开启cmd运行 ...

  9. 201621123007 Java程序设计第一周 学习总结

    第一周-Java基本概念 201621123007 <Java程序设计> 第一周学习总结 1. 本周学习总结 java是面向对象的一类语言,三大特征:封装性,继承性,多态性. jdk jr ...

随机推荐

  1. Android编译系统中的Android.bp【转】

    本文转载自: 转自:http://note.qidong.name/2017/08/android-blueprint/ Android编译系统中的Android.bp.Blueprint与Soong ...

  2. 2-sat相关复习

    2-sat相关复习 noi曾经考过,谁能说得准呢 sat问题 通俗的sat问题表述一般是这样的:有很多个集合,每个集合里面有若干元素,现给出一些取元素的规则,要你判断是否可行,可行则给出一个可行方案. ...

  3. 密码发生器|2012年蓝桥杯B组题解析第八题-fishers

    (10')密码发生器 在对银行账户等重要权限设置密码的时候,我们常常遇到这样的烦恼:如果为了好记用生日吧,容易被破解,不安全:如果设置不好记的密码,又担心自己也会忘记:如果写在纸上,担心纸张被别人发现 ...

  4. Docker:Stacks

    Prerequisites Install Docker version 1.13 or higher. Get Docker Compose as described in Part 3 prere ...

  5. Ajax - 发送请求原理

    1,什么是ajax? Asynchronous JavaScript and XML(当然现在xml已经由json代替): 主要是用于前后台的交互(表单提交已经被废弃): 使用场景:前台获取数据.表单 ...

  6. Java—网络编程基础

    URL的应用: 获得网页源代码可以用字节流.字符流,流的获取可以用url.openStream(),也可以用con.getInputStream(): 字节流: URL url = new URL(& ...

  7. 草珊瑚的redux使用方式

    前言 阮大师写入门教程能力一流. 首推它的Redux三篇入门文章. http://www.ruanyifeng.com/blog/2016/09/redux_tutorial_part_one_bas ...

  8. Shell中的IFS

    一.IFS 介绍 Shell 脚本中有个变量叫 IFS(Internal Field Seprator) ,内部域分隔符.完整定义是The shell uses the value stored in ...

  9. 无视编码都统一转成unicode 然后截断 例如 。“发发发发发发” 操作之后显示为 “发发发发...”

    -- local function checkPlayName( str ) -- str = Utils.utf8_to_unicode(str)-- local retStr = "&q ...

  10. php中if(\$a==\$b)和if(\$a=\$b)什么区别?

    <?php // if($a==$b)和if($a=$b)什么区别? $a = 1; $b = 1; if ($a == $b) { // 通过 echo '通过'.PHP_EOL; } if ...