zoukankan      html  css  js  c++  java
  • Java学习(八)

    class Cust {
        String name;
    	int ID;
    	String PWD;
    	int money;
    	static String bankName = "建设银行";
    	int selfNum = 0;
    	static int allNum = 0;
    	
    	Cust(){
    	    name = "";
    		ID = 0;
    		PWD = "";
    		money = 0;
    		allNum++;
    		selfNum = allNum;
    	}
    	Cust(String newName,int newID,String newPWD,int newMoney){
    	    name = newName;
    		ID = newID;
    		PWD = newPWD;
    		money = newMoney;
    		allNum++;
    		selfNum = allNum;
    	}
    	void getMoney(int newMoney){
    	    money = money - newMoney;
    	}
    	void setMoney(int neawMoney){
    	    money = money + newMoney;
    	}
    	void search(){
    	    System.out.println("所属银行:" + Cust.bankName);
    		System.out.println("您是本银行的" + allNum + "个顾客中的第" + selfNum + "个顾客");
    		System.out.println("户名:" + name);
    		System.out.println("账号:" + ID);
    		System.out.println("账号余额" + money);
    	}
    	void changePWD(String newPWD){
    	    PWD = newPWD;
    	}
    	void setInfo(String newName,int newID,String newPWD,int newMoney){
    	    name = newName;
    		ID = newID;
    		PWD = newPWD;
    		money = newMoney;
    	}
    }
    class Demo{
        public static void main(String[] args){
    	    Cust st1 = new Cust("Tom",100,"11111",10000);
    		Cust st2 = new Cust();
    		
    		st1.setMoney(5000);
    		st1.getMoney(3000);
    		st1.changePWD("Tom");
    		st1.search();
    		
    		st2.setInfo("Jerry",200,"22222",10000);
    		st2.setMoney(10000);
    		st2.getMoney(5000);
    		st2.changePWD("Jerry");
    		st2.search();
    		}
    	}
    

      

    ·构造方法的重载

  • 相关阅读:
    基于python的种子搜索网站(三)项目部署
    Python 的 Geth 封装库 PyGeth
    主题: 002.04 Tkinter 星空大战
    python 打飞机项目 (实战一)
    python使用mysql的一些坑
    Python 变量与运算符
    字符流
    IO字节流(2)
    端口转发
    IO流(1)
  • 原文地址:https://www.cnblogs.com/sheril/p/5576152.html
Copyright © 2011-2022 走看看