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+"毫安·时电量"); } }