多少努力 就得多少分 : 65
class Animal
{
private int legs;
private int steps;
public void Animal()
{
setLegs(4);
}
public void Animal(int L)
{
setLegs(L);
}
public void eat()
{
System.out.println("Eating.....");
}
public void move()
{
if (steps!=10)
{
steps ++;
System.out.println("Moving...");
}else{System.out.println("Maximum steps! Can not move!!");}
}
public void move(int S)
{
if (steps+S {
steps=steps+S;
System.out.println("Moving " + S +" steps!");
}else{
if (steps >= 10 || steps+S >=10)
{
System.out.println("Maximum steps! Can not move!!");
}
}
}
public void back(int S)
{
if (steps!=0)
{
steps --;
System.out.println("Back " + S + " Steps");
}else{System.out.println("Can not Back!!");}
}
public void setLegs(int L)
{
if((L != 0 )||( L != 2) ||( L !=4))
{
System.out.println("Wrong number of legs!");return;
}else legs=L;
}
public int getLegs()
{
return legs;
}
public int getSteps()
{
return steps;
}
}
public class java1101
{
public static void main(String[] args)
{
Animal Cow = new Animal();
Animal Bird = new Animal();
Animal Taco = new Animal();
int steps;
Cow.Animal(4);
Bird.Animal(2);
Taco.Animal(8);
System.out.println("");
System.out.println("Bird");
Bird.move(2);
Bird.eat();
Bird.move(7);
Bird.eat();
Bird.move(4);
steps=Bird.getSteps();
System.out.println("Bird steps"+ steps);
System.out.println("");
System.out.println("Cow");
Cow.eat();
Cow.eat();
Cow.move(6);
Cow.back(4);
Cow.move(2);
Cow.back(3);
steps=Cow.getSteps();
System.out.println("Cow steps"+ steps);
}
}
留言列表