zoukankan      html  css  js  c++  java
  • 实验六:类的封装

    源代码:

    package 银行账户;
    import java.util.Scanner;
    public class Account {
    String zhanghu;
    double yue;//余额
    double ck;
    double qk;
    long kaihu;
    long xiaohu;

    public Account(String zh,double ye,long kh,long xh)
    {
    zhanghu=zh;
    yue=ye;
    kaihu=kh;
    xiaohu=xh;

    }
    //开户
    void getkaihu()
    {
    Scanner sc1=new Scanner(System.in);
    System.out.println("请输入身份证号:");
    long kai=sc1.nextInt();
    System.out.println("您的开户账号为:6321221999"+kai );
    }
    //销户
    void getxiaohu()
    {
    Scanner sc1=new Scanner(System.in);
    System.out.println("请输入身份证号:");
    long xiao=sc1.nextInt();
    System.out.println("您的销户账号为:6321221999"+xiao );
    System.out.println("此账号已销户");
    }
    //存款
    void getcunkuan()
    {
    Scanner sc1=new Scanner(System.in);
    System.out.println("请输入存款数目:");
    double cun=sc1.nextDouble();
    yue=yue+cun;
    System.out.println("您的存款数目为:"+cun+"元");
    }
    //取款
    void getqukuan()
    {
    Scanner sc1=new Scanner(System.in);
    System.out.println("请输入取款数目:");
    double qu=sc1.nextDouble();
    if(qu>yue)
    {
    System.out.println("您的余额不足");
    }
    else {
    yue=yue-qu;
    System.out.println("您的取款数目为:"+qu+"元");
    }
    }
    //查询余额
    double getchaxunyue()
    {
    return yue;
    }


    public static void main(String[] args) {
    Account yh= new Account("马云",00000.00,00000,00000);
    System.out.println("当前用户:"+yh.zhanghu);
    System.out.println("请选择服务类型:");
    System.out.println("1.存款");
    System.out.println("2.取款");
    System.out.println("3.余额查询");
    System.out.println("4.开户");
    System.out.println("5.销户");
    Scanner sc=new Scanner(System.in);

    while(true)
    {
    int x=sc.nextInt();
    if(x==1||x==2||x==3||x==4||x==5){
    switch(x){
    case 1:
    System.out.println("****存款*****");
    yh.getcunkuan();
    break;
    case 2:
    System.out.println("****取款****");
    yh.getqukuan();
    case 3:
    System.out.println("****余额查询***");
    System.out.println("当前余额为:"+yh.getchaxunyue()+"元");
    break;
    case 4:
    System.out.println("****开户****");
    yh.getkaihu();
    break;
    case 5:
    System.out.println("****销户****");
    yh.getxiaohu();
    break;
    }
    }
    else{
    break;
    }

    }
    }
    }

    结果:

    当前用户:雨点
    请选择服务类型:
    1.存款
    2.取款
    3.余额查询
    4.开户
    5.销户
    4
    ****开户****
    请输入身份证号:
    731322
    您的开户账号为:6321221999731322
    1
    ****存款*****
    请输入存款数目:
    99
    您的存款数目为:99.0元
    2
    ****取款****
    请输入取款数目:
    0
    您的取款数目为:0.0元
    ****余额查询***
    当前余额为:99.0元
    3
    ****余额查询***
    当前余额为:99.0元
    5
    ****销户****
    请输入身份证号:
    00000
    您的销户账号为:63212219990
    此账号已销户

    心得:

    1.Java中类的封装和C++中类的封装有很多相似的地方

    2.在编写代码的时候还有点生疏,还需要多去了解关于Java的程序编写。

  • 相关阅读:
    更改默认alert框体
    自定义垂直拖动的seekbar进度条
    android适配pad和部分手机底部虚拟按键+沉浸式状态栏
    解决studio的URI is not registered (Setting|Language&Frameworks|Schemas and DTDs)
    王者荣耀是怎样炼成的(二)《王者荣耀》unity安装及使用的小白零基础入门
    王者荣耀是怎样炼成的(一)《王者荣耀》用什么开发,游戏入门,unity3D介绍
    使用python(command line)出现的ImportError: No module named 'xxx'问题
    Android Studio生成keystore签名文件步骤讲解
    greendao数据库初次使用的配置及多表关联的初始化
    android视频双向实时通讯的横竖屏切换
  • 原文地址:https://www.cnblogs.com/Z-js/p/10706080.html
Copyright © 2011-2022 走看看