zoukankan      html  css  js  c++  java
  • 实验报告二

    public class Rectangle {
        
    
            public double width;
            public double height;
            public String color;
            public double getWidth(){
                return width;
            }
            public void setWidth(double i) {
                this.width = i;
            }
            public double getHeight(){
                return height;
            }
            public void setHeight(double h) {
                this.height = h;
            }
            public String getColor() {
                return color;
            }
            public void setColor(String c) {
                this.color = c;
            }
            public double getArea() {
                return height*width;
            }
            public double getLength() {
                return (height+width)*2;
            }
    
        
    
    }

    import java.util.Scanner;
    public class Account {
        public int id;
        public int password;
        public String name;
        public int money;
        
                     public Account(int id, int password, String name, int money) {
            this.id = id;
            this.password = password;
            this.name = name;
            this.money = money;
        }
        public void show(){
            System.out.println("账户:" + id);
            System.out.println("姓名:" + name);
            System.out.println("余额:" + money);
        }
        public void takeMoney(){
            while(true){
                Scanner sc = new Scanner(System.in);
                System.out.println("输入密码");
                int pass = sc.nextInt();
                if(pass == password){
                    System.out.println("取款金额:");
                    int withdrawals = sc.nextInt();
                    if(withdrawals <= money) {
                        money= money-withdrawals;
                        System.out.println("余额为:" + money);
                    }
                                                                    else {
                        System.out.println("当前余额不足" );
                    }
                    break;
                }
                                                    else{
                    System.out.println("密码错误,请重新输入!");
                }
            }
        }
        
        public void saveMoney(int moneys){    
            money = money+moneys;
            System.out.println("此次存款为:" + moneys);
            System.out.println("账户余额为:" + money);
        }
        
        public static void main(String[] args) {
            Account acc = new Account(10010,123456,"陈果",0);
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入需要执行的操作");
            System.out.println("1银行账户信息");
            System.out.println("2取款操作");
            System.out.println("3存款操作");
            System.out.println("4退出系统");
            int s = sc.nextInt();
                switch(s) {
                case 1:
                    System.out.println("银行账户");
                    acc.show();
                    break;
                case 2:
                    System.out.println("取款");
                    acc.takeMoney();
                    break;
                case 3:
                    System.out.println("存款");
                    acc.saveMoney(1000);
                    break;
                case 4:
                    System.exit(0);
                    break;
                }
        }
     
    }
     

  • 相关阅读:
    java基础 第六章 下(抽象数据类型,面向过程,面向对象)
    java基础 第六章 上(二维数组)
    java基础 第五章 下(选择排序,冒泡排序)
    java基础 第五章 上(数组的第二种定义方法)
    java基础 补充(JVM 划分内存)
    java基础 第四章 下(数组)
    java基础 第四章 上(加载过程,重载)
    java基础 第三章 下(方法)
    java基础 第三章 上(终止循环 break,continue)
    Annotation 注解
  • 原文地址:https://www.cnblogs.com/chenguohhw/p/11537803.html
Copyright © 2011-2022 走看看