Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- public class Car{
- private int speed;
- private String name;
- private int location = 0;
- public int getLocation() {
- return location;
- }
- public void setLocation(int location) {
- this.location = location;
- }
- private static int maxSpeedForAll = 120;
- private static int minSpeedForAll = 0;
- public static int getMinSpeedForAll() {
- return minSpeedForAll;
- }
- public static void setMinSpeedForAll(int minSpeedForAll) {
- Car.minSpeedForAll = minSpeedForAll;
- }
- public Car(String name, int speed) {
- setSpeed(speed);
- setName(name);
- }
- public static int getMaxSpeedForAll() {
- return maxSpeedForAll;
- }
- public static void setMaxSpeedForAll(int maxSpeedForAll) {
- Car.maxSpeedForAll = maxSpeedForAll;
- }
- public int getSpeed() {
- return speed;
- }
- public void setSpeed(int speed) {
- if (speed <= maxSpeedForAll) {
- this.speed = speed;
- } else {
- this.speed = maxSpeedForAll;
- }
- }
- Random generator = new Random();
- public int randomSpeedChange(){
- int result;
- result = generator.nextInt(20)+1;
- return result;
- }
- public void accelerate(int speed, int randomSpeedChange) {
- if (randomSpeedChange > 10){
- speed += randomSpeedChange;
- }
- }
- public void decelerate(int speed,int randomSpeedChange){
- if (randomSpeedChange <= 10){
- speed -= randomSpeedChange;
- }
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String toString() {
- String result;
- result = name + " ";
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement