Advertisement
Guest User

Untitled

a guest
Feb 27th, 2015
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. import java.util.Random;
  2. public class Car{
  3. private int speed;
  4. private String name;
  5. private int location = 0;
  6.  
  7. public int getLocation() {
  8. return location;
  9. }
  10.  
  11. public void setLocation(int location) {
  12. this.location = location;
  13. }
  14.  
  15. private static int maxSpeedForAll = 120;
  16. private static int minSpeedForAll = 0;
  17.  
  18. public static int getMinSpeedForAll() {
  19. return minSpeedForAll;
  20. }
  21.  
  22. public static void setMinSpeedForAll(int minSpeedForAll) {
  23. Car.minSpeedForAll = minSpeedForAll;
  24. }
  25.  
  26. public Car(String name, int speed) {
  27. setSpeed(speed);
  28. setName(name);
  29. }
  30.  
  31. public static int getMaxSpeedForAll() {
  32. return maxSpeedForAll;
  33. }
  34.  
  35. public static void setMaxSpeedForAll(int maxSpeedForAll) {
  36. Car.maxSpeedForAll = maxSpeedForAll;
  37. }
  38.  
  39. public int getSpeed() {
  40. return speed;
  41. }
  42.  
  43. public void setSpeed(int speed) {
  44. if (speed <= maxSpeedForAll) {
  45. this.speed = speed;
  46. } else {
  47. this.speed = maxSpeedForAll;
  48. }
  49.  
  50. }
  51. Random generator = new Random();
  52.  
  53. public int randomSpeedChange(){
  54. int result;
  55. result = generator.nextInt(20)+1;
  56. return result;
  57. }
  58. public void accelerate(int speed, int randomSpeedChange) {
  59. if (randomSpeedChange > 10){
  60. speed += randomSpeedChange;
  61. }
  62.  
  63. }
  64. public void decelerate(int speed,int randomSpeedChange){
  65. if (randomSpeedChange <= 10){
  66. speed -= randomSpeedChange;
  67. }
  68. }
  69.  
  70. public String getName() {
  71. return name;
  72. }
  73.  
  74. public void setName(String name) {
  75. this.name = name;
  76. }
  77.  
  78. public String toString() {
  79. String result;
  80. result = name + " ";
  81. return result;
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement