码迷,mamicode.com
首页 > 其他好文 > 详细

代码练习----以电脑为例

时间:2015-12-14 10:36:31      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:

package com.hanqi;

public class Computer 
   {

    private String pinP;//品牌

    public String getPinP() 
    {
        return pinP;
    }

    public void setPinP(String pinP) 
    {
        this.pinP = pinP;
    }
    private String yanS;//颜色

    public void setYanS(String yanS) {
        this.yanS = yanS;
    }
    private String zhuangT = "开机";//状态

    public String getZhuangT() 
    {
        return zhuangT;
    }
    private double dianCRL;//电池容量

    public double getDianCRL() {
        return dianCRL;
    }
    public void setDianCRL(double dianCRL) {
        this.dianCRL = dianCRL;
    }
    private double dianL=0;//电量
    
    public double getDianL(int i) {
        return dianL;
    }
    public void setDianL() {
        this.dianL = dianL;
    }
    double dangQDL = this.dianCRL - this.dianL;
    public void chongD(double dianL)//充电
    {
    
        if(dianCRL <= 0)
        {
            System.out.println("未装电池,请连接电源线");
            return;
        }
        
        else if(dangQDL <=0.05)
        {
            System.out.println("电量不足,即将关机");
            return;
        }
        else 
        {
            System.out.println("电量已满,请断开电源线");
        
        }
}
    public Computer(String pinP)
    {
        System.out.println("实例化电脑的品牌是"+pinP);
        this.pinP = pinP;
    }
    public static void main(String[] args)
    {
        Computer computer = new Computer("联想");
        
        computer.chongD(600);
        computer.setDianCRL(500);
        computer.getDianL(400);
        computer.setYanS("银色");

        
        System.out.println("电脑的品牌是"+computer.pinP);
        System.out.println("颜色是"+computer.yanS+",状态是"+computer.zhuangT);
        System.out.println("充了"+computer.dianL+"毫安·时电量");
    }
    }

技术分享

代码练习----以电脑为例

标签:

原文地址:http://www.cnblogs.com/0927wyj/p/5044216.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!