实验六

package 实验六;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
public class Account {
    String zhanghao;    //账号
    String xingming;    //姓名
    String kaihushijian;     //开户时间
    String shenfenzhenghao;   //身份证号
    long yue;        //余额
    Scanner sc=new Scanner (System.in);
        public void kaihu() {
        System.out.println("请输入开户账号、姓名、身份证号码、开户金额");
         zhanghao=sc.next();
         xingming=sc.next();
         shenfenzhenghao=sc.next();
         yue=sc.nextLong();
         System.out.println("账户建立成功!");
    }
    public long cunkuan() {

        System.out.println("请输入存款金额:");
        long shue=sc.nextLong();
        yue=yue+shue;
        System.out.println("存款成功!");
        System.out.println("余额:"+yue);
        return yue;
    }
    public long qukuan() {
        System.out.println("请输入取款金额");
        long jine=sc.nextLong();
        yue=yue-jine;
        if(yue>=0) {
            System.out.println("取款成功");
            System.out.println("余额:"+yue);}
        else
            System.out.println("对不起,您的余额不足!");
        return yue;
    }
    public String kaiHushijian(){
        Date date = new Date();
        SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd :hh:mm:ss");
        this.kaihushijian=dateFormat.format(date);
        return kaihushijian;
        }
    public void chaxun() {
        System.out.println("账号:"+zhanghao);
        System.out.println("姓名:"+xingming);
        System.out.println("开户时间"+kaiHushijian());
        System.out.println("身份证号码:"+shenfenzhenghao);
        System.out.println("余额"+yue);
    }
    public void finalize()//销户
    {
        System.out.println("销户成功!");
    }
    @SuppressWarnings({ "resource" })
    public static void main(String[] args) 
    {
        Account a=new Account();
        
        for(int i = 1;i<=6;i++) {
            System.out.println("1.开户");
            System.out.println("2.存款");
            System.out.println("3.取款");
            System.out.println("4.查询");
            System.out.println("5.销户");
            System.out.println("0.退出 ");
            Scanner sc=new Scanner(System.in);
            System.out.println("请输入您要选择操作的序号:");

            int option=sc.nextInt();
            if(option==0)
                break;
        switch(option){//选择服务
        case 1 :
            a.kaihu();
            a.chaxun();
            break;
        case 2:
            a.cunkuan();
            break;
        case 3:
            a.qukuan();
            break;
        case 4:
            a.chaxun();
            break;
        case 5:
            a.finalize();
            break;
        default : System.out.println("对不起,您的输入有误");
        break;
        }
        }
    }
}

实验六实验六

上一篇:约数


下一篇:函数初识