写一个Java编程

定义一个People类,要求如下:
(1)成员变量:name、height、weight分别表示姓名、身高(cm)和体重(kg)。
(2)构造方法通过参数实现对成员变量的赋初值操作。
(3)成员方法int check(),该方法返回0 、1、-1分别表示标准、过胖或过瘦)。判断方法是:用身高减去110作为参考体重,超过参考体重5kg以上的,为“过胖”;低于参考体重5kg以上的,为“过瘦”;在(参考体重-5kg)和(参考体重+5kg)之间的,为“标准”。
(4)在main方法中,输入50个学生的信息(姓名、身高和体重),分别输出标准、过胖或过瘦的人数(必须通过调用check()方法实现)。

package yourPackageName;

import java.math.BigDecimal;

public class People {

// (1)成员变量:name、height、weight分别表示姓名、身高(cm)和体重(kg)。
// 姓名
private String name;
// 身高(cm)
private int height;
// 体重(kg)
private int weight;

/**
 * 构造方法通过参数实现对成员变量的赋初值操作
 */
People(String name, int height, int weight) {
this.name = name;
this.height = height;
this.weight = weight;
}

/**
 * 该方法返回0、1、-1分别表示标准、过胖或过瘦)。 判断方法是:用身高减去110作为参考体重,超过参考体重5kg以上的,为“过胖”;
 * 低于参考体重5kg以上的 ,为“过瘦”;在(参考体重-5kg)和(参考体重+5kg)之间的,为“标准”。
 */
int check() {
int standard = this.height - 110;
if (this.weight > standard + 5) {
return 1;
}
if (this.weight < standard - 5) {
return -1;
}
return 0;
}

@Override
public String toString() {
return new StringBuffer(this.name).append(",").append(this.height).append("cm,").append(this.weight).append("kg,").append(this.check()).toString();
}

/**
 * (4)在main方法中,输入50个学生的信息(姓名、身高和体重),分别输出标准、过胖或过瘦的人数(必须通过调用check()方法实现)。
 * 
 * @return void
 */
public static void main(String[] args) {
int aCount = 0;
int bCount = 0;
int cCount = 0;
for (int i = 0; i < 50; i++) {
// 创建50个身材体重随机的People
People man = new People("People" + i, new BigDecimal(Math.random() * 50).intValue() + 150, new BigDecimal(Math.random() * 60).intValue() + 40);
switch (man.check()) {
case 0:
aCount++;
break;
case 1:
bCount++;
break;
case -1:
cCount++;
break;
}
}
System.out.println("标准身材:" + aCount + "个");
System.out.println("过胖:" + bCount + "个");
System.out.println("过瘦:" + cCount + "个");
}

}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-01-06
("第"+i+"编写……);

运行效果是:
第i编写

i++是:例如i=1,运行i++后,是2,++是自增,也就是+1
第2个回答  2020-05-02
("第"+i+"编写……);
i:表示是第几个循环,+:表示字符串连接;
i++
i:本次循环;
+:表示在本次循环的基础上加1;
第3个回答  2020-02-12
这个问题简单+i+取自
第"+i+"编写……;
这句话

i是你的变量,就是你的数字1,2,3.....
这只是把数据拼到
第1(取值1-100)次编写

i++
就是执行到这里再返回循环之前先加一,

原本i等于1返回去的i就等于2,有什么问题欢迎继续提问。。。。。。。。。。。。
第4个回答  2019-12-29
+i+
因为是在
System.out.println()中
所以它的意思是
输出
第i个XXXX
i输出时变成整数
如:第1个
第2个。。。
i++
的意思是
i=i+1;
相似回答