Created
October 26, 2015 11:31
-
-
Save AnnaBoro/dfc7d04fde88ae1496e4 to your computer and use it in GitHub Desktop.
lesson4 - Frame13
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; | |
public class RunTank { | |
public static void main(String[] args) { | |
RunTank runTank = new RunTank(); | |
runTank.printTankInfo(); | |
} | |
public void printTankInfo() { | |
Tank[] tanks = new Tank[5]; | |
for(int i = 0; i < tanks.length; i++) { | |
tanks[i] = new Tank(); | |
tanks[i].setColor("black"); | |
tanks[i].setCrew(i + 1); | |
tanks[i].setMaxSpeed(i + 25); | |
System.out.println(i + " Tank color: " + tanks[i].getColor() + " crew: " + tanks[i].getCrew() | |
+ " maxSpeed: " + tanks[i].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; | |
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; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment