import java.util.Random;
//开发一个人类,具有实例属性身高,体重,星座,有如下实例方法:
//a)初始化方法:内部随机产生身高(140-200cm)和体重(40-300kg)
//b)获得身高
//c)获得体重
//d)设置星座(注意限制)
//e)得到星座
public class Human {
String star;
int XZ;
int weight=0;
int height=0;
Random rand = new Random();
public void setWeight() {
int _weight= rand.nextInt(200 - 140 + 1) + 140;
weight=_weight;
}
public int getWeight() {
return weight;
}
public void setHeight() {
int _height = rand.nextInt(300-40+1)+40;
height=_height;
}
public int getHeight() {
return height;
}
public void setStar() {
int _star = rand.nextInt(12);
switch (_star) {
case 1:
System.out.println("水瓶座");
break;
case 2:
System.out.println("双鱼座");
break;
case 3:
System.out.println("白羊座");
break;
case 4:
System.out.println("金牛座");
break;
case 5:
System.out.println("双子座");
break;
case 6:
System.out.println("巨蟹座");
break;
case 7:
System.out.println("狮子座");
break;
case 8:
System.out.println("处女座");
break;
case 9:
System.out.println("天秤座");
break;
case 10:
System.out.println("天蝎座");
break;
case 11:
System.out.println("射手");
break;
case 12:
System.out.println("摩羯座");
break;
default:
break;
}
}
public String getStar() {
return star;
}
}
public class HumanTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
Human a=new Human();
a.setWeight();
a.getWeight();
System.out.println("体重为:"+a.getWeight());
a.setHeight();
a.getHeight();
System.out.println("身高为:"+a.getHeight());
a.setStar();
a.getStar();
}
}
import java.util.Random;//开发一个人类,具有实例属性身高,体重,星座,有如下实例方法://a)初始化方法:内部随机产生身高(140-200cm)和体重(40-300kg)//b)获得身高//c)获得体重//d)设置星座(注意限制)//e)得到星座public class Human { String star; int XZ; int weight=...