1、:
猜数字游戏:一个类A有一个成员变量v,有一个初值100。定义一个类,对A类的成员变量v进行猜。如果大了则提示大了,小了则提示小了。等于则提示猜测成功。
public class Question1{
int v=100;
Question1(int VB){
if (VB
System.out.println("smaller");
else if (VB>v)
System.out.println("bigger");
else
System.out.println("right");
}
}
public class TestA{
public static void main(String args[]){
Question1 q = new Question1(30);
Question1 q1 = new Question1(120);
Question1 q2 = new Question1(100);;
}
}
2、
请定义一个交通工具(Vehicle)的类,其中有: 属性:速度(speed),体积(size)等等 方法:移动(move()),设置速度(setSpeed(int
speed)),加速speedUp(),减速speedDown()等等.
最后在测试类Vehicle中的main()中实例化一个交通工具对象,并通过构造方法给它初始化speed,s