Created
November 4, 2015 13:11
-
-
Save AnnaBoro/3af370152f20446b8d59 to your computer and use it in GitHub Desktop.
TankInheritance2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package lesson4.tankInheritance; | |
/** | |
* Created by anna on 04.11.15. | |
*/ | |
public class BT7 extends Tank { | |
private int maxSpeed = 72; | |
public BT7() { | |
} | |
public BT7(int maxSpeed) { | |
this.maxSpeed = maxSpeed; | |
} | |
@Override | |
public int getMaxSpeed() { | |
return maxSpeed; | |
} | |
@Override | |
public void move() { | |
System.out.println("BT7 is moving"); | |
} | |
@Override | |
public String toString() { | |
return "Name: BT7, " +" Tank color: " + getColor() + ", crew: " + getCrew() | |
+ ", maxSpeed: " + getMaxSpeed(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package lesson4.tankInheritance; | |
public class RunTank2 { | |
public static void main(String[] args) { | |
Tank tank = new Tank("violet", 2, 30); | |
BT7 bt7 = new BT7(); | |
T34 t34 = new T34(); | |
Tiger tiger = new Tiger(); | |
tank.move(); | |
System.out.println(tank.toString()); | |
bt7.move(); | |
System.out.println(bt7.toString()); | |
t34.move(); | |
System.out.println(t34.toString()); | |
tiger.move(); | |
System.out.println(tiger.toString()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package lesson4.tankInheritance; | |
/** | |
* Created by anna on 04.11.15. | |
*/ | |
public class T34 extends Tank { | |
private int maxSpeed = 50; | |
public T34() { | |
} | |
public T34(String color, int crew, int maxSpeed) { | |
super(color, crew, maxSpeed); | |
} | |
public T34(String color, int crew, int maxSpeed, int maxSpeed1) { | |
super(color, crew, maxSpeed); | |
maxSpeed = maxSpeed1; | |
} | |
public T34(int maxSpeed) { | |
this.maxSpeed = maxSpeed; | |
} | |
@Override | |
public int getMaxSpeed() { | |
return maxSpeed; | |
} | |
@Override | |
public void move() { | |
System.out.println("T34 is moving"); | |
} | |
@Override | |
public String toString() { | |
return "Name: T34, " +" Tank color: " + getColor() + ", crew: " + getCrew() | |
+ ", maxSpeed: " + getMaxSpeed(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package lesson4.tankInheritance; | |
public class Tank { | |
private String color; | |
private int crew; | |
private int maxSpeed; | |
public Tank() { | |
} | |
public Tank(String color, int crew, int maxSpeed) { | |
this.color = color; | |
this.crew = crew; | |
this.maxSpeed = maxSpeed; | |
} | |
public String getColor() { | |
return color; | |
} | |
public void setColor(String color) { | |
this.color = color; | |
} | |
public int getCrew() { | |
return crew; | |
} | |
public void setCrew(int crew) { | |
if (crew < 0) { | |
this.crew = 0; | |
} | |
else { | |
this.crew = crew; | |
} | |
} | |
public int getMaxSpeed() { | |
return maxSpeed; | |
} | |
public void setMaxSpeed(int maxSpeed) { | |
if (maxSpeed > 150) { | |
this.maxSpeed = 150; | |
} | |
else { | |
this.maxSpeed = maxSpeed; | |
} | |
} | |
public void move() { | |
System.out.println("Tank is moving"); | |
} | |
public String toString() { | |
return "Name: Tank, " +" Tank color: " + getColor() + ", crew: " + getCrew() | |
+ ", maxSpeed: " + getMaxSpeed(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package lesson4.tankInheritance; | |
/** | |
* Created by anna on 04.11.15. | |
*/ | |
public class Tiger extends Tank { | |
private int maxSpeed = 36; | |
private int armor = 1; | |
public Tiger() { | |
} | |
public Tiger(int maxSpeed, int armor) { | |
this.maxSpeed = maxSpeed; | |
this.armor = armor; | |
} | |
@Override | |
public int getMaxSpeed() { | |
return maxSpeed; | |
} | |
public int getArmor() { | |
return armor; | |
} | |
@Override | |
public void move() { | |
System.out.println("Tiger is moving"); | |
} | |
@Override | |
public String toString() { | |
return "Name: Tiger, " +" Tank color: " + getColor() + ", crew: " + getCrew() | |
+ ", maxSpeed: " + getMaxSpeed(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment