标签:
package duixiang; public class NewClass { public String pinpai; public String color; public int dianchirl; public int dianliang; public NewClass(String pinpai, String color, int dianchirl) { System.out.println("品牌是" + pinpai + " ,颜色是" + color + " , 电池容量为" + dianchirl); } //充电 public void cd(int cd) { int x = dianliang; dianliang +=cd; if(dianliang >= 100) { System.out.println("电池已经充满。"); dianliang = 100; } System.out.println("充电" + cd + "% , 当前电量" + dianliang + "% "); } //电池已用时间 public void yysj(int yysj) { if(yysj >= 3) { dianliang = 7; System.out.println("电池剩余" + dianliang + "% ,电脑即将关机"); } else { System.out.println("您可以继续使用。"); } } }
package duixiang; public class Newsthh { public static void main(String[] args) { // TODO Auto-generated method stub NewClass pc = new NewClass("gateway" , "white" , 47520); pc.dianliang = 7; pc.cd(99); pc.yysj(2); } }
结果为
品牌是gateway ,颜色是white , 电池容量为47520
电池已经充满。
充电99% , 当前电量100%
您可以继续使用。
标签:
原文地址:http://www.cnblogs.com/shadowduke/p/4876459.html