共饮水井水
Test_9.java
package xxb;
public class Test_9 {
static int waterAmount;
int peopleNmuber;
String name;
Test_9 (String s){
name =s ;
}
static void setWaterAmount(int m) {
if(m>0)
waterAmount =m;
}
void drinkWater(int n) {
if(waterAmount-n>=0) {
waterAmount =waterAmount-n;
System.out.println(name+"喝了"+n+"升水");
}else
waterAmount=0;
}
public static int lookWaterAmount() {
return waterAmount;
}
public int getPeopleNmuber() {
return peopleNmuber;
}
public void setPeopleNumber(int n) {
this.peopleNmuber = n;
}
}
UseTest_9.java
package xxb;
public class UseTest_9 {
public static void main(String[] args) {
Test_9.setWaterAmount(200);
int leftWater=Test_9.waterAmount;
System.out.println("水井中有"+leftWater+"升水");
Test_9 zhaozhuang=new Test_9("赵庄");
Test_9 majiahezi=new Test_9("马家河子");
zhaozhuang.setPeopleNumber(80);
majiahezi.setPeopleNumber(120);
zhaozhuang.drinkWater(50);
leftWater =majiahezi.lookWaterAmount();
String name= majiahezi.name;
System.out.println(name+"发现水井中有"+leftWater+"升水");
majiahezi.drinkWater(100);
leftWater=zhaozhuang.lookWaterAmount();
name=zhaozhuang.name;
System.out.println(name+"发现水井中有"+leftWater+"升水");
int peopleNumber=zhaozhuang.getPeopleNmuber();
System.out.println("赵庄的人口:"+peopleNumber);
peopleNumber=majiahezi.getPeopleNmuber();
System.out.println("马家河子的人口:"+peopleNumber);
}
}
求方程的根
|