标签:
---恢复内容开始---
public class Dog { private String color; private String pinpai; private double tizhong; private double shengao; private double shiliang; private double dangqiantz=10; public double getdangqiantz() { return dangqiantz; } public void weishi(double weishiliang) { if(weishiliang<0) { System.out.println("狗吃的什么"); } else if(dangqiantz+weishiliang>this.shiliang) { System.out.println("狗撑死了"); } else { this.dangqiantz+=weishiliang; System.out.println("狗吃饱了"); } } private double yundongzjl=0; public double getyundongzjl() { return this.yundongzjl; } public void yundong(double yundongjl,double xiaohao) { if(dangqiantz<=0) { System.out.println("狗饿死了"); } else if(yundongjl<=0||xiaohao<0) { System.out.println("什么狗"); } else { double dangqianxh=yundongjl*xiaohao; this.dangqiantz-=dangqianxh; if(dangqiantz<0) { this.dangqiantz=0; System.out.println("狗已经饿死了"); } this.yundongzjl+=yundongjl; System.out.println("总共跑了"+yundongzjl+"米"); } } public String getColor() { return color; } public void setColor(String color) { this.color = color; } public String getPinpai() { return pinpai; } public void setPinpai(String pinpai) { this.pinpai = pinpai; } public double getTizhong() { return tizhong; } public void setTizhong(double tizhong) { this.tizhong = tizhong; } public double getShengao() { return shengao; } public void setShengao(double shengao) { this.shengao = shengao; } public Dog(String pinpai, double tizhong) { super(); this.pinpai = pinpai; this.tizhong = tizhong; } public static void main(String[] args) { Dog mydog=new Dog("茶杯",10); System.out.println("狗品牌:"+mydog.getPinpai()); System.out.println("体重:"+mydog.getTizhong()); mydog.weishi(10); System.out.println("当前体重:"+mydog.getdangqiantz()); mydog.yundong(3, 1); System.out.println("当前体重:"+mydog.getdangqiantz()); System.out.println("当前总里程:"+mydog.getyundongzjl()); }
---恢复内容结束---
标签:
原文地址:http://www.cnblogs.com/1ming/p/5249422.html