Ad
Code
Diff
  • import java.util.*;
    
    class Vehicle {
    
        int currentSpeed;
        Road currentRoad = new Road(60);
    
        public void setCurrentSpeed(int... accelerations) {
            currentSpeed = Arrays.stream(accelerations).sum();
        }
        
        public int getCurrentSpeed() {
            return currentSpeed;
        }
    
        public boolean isWithinSpeedLimit() {
            return currentSpeed <= currentRoad.speedLimit;
        }
      
        public int getTicketCost() {
                if (currentSpeed>=currentRoad.speedLimit+10&&currentSpeed<currentRoad.speedLimit+19) {
                  return 100;
               } else if (currentSpeed>=currentRoad.speedLimit+20&&currentSpeed<currentRoad.speedLimit+29) {
                  return 250;
               } else if (currentSpeed>=currentRoad.speedLimit+30) {
                  return 500;
               }
           return 0;
        }
    }
    
    final class Road {
    
        int speedLimit;
    
        public Road(int speedLimit) {
            this.speedLimit = speedLimit;
        }
    }
    
    • import java.util.*;
    • class Vehicle {
    • int currentSpeed;
    • Road currentRoad = new Road(60);
    • public void setCurrentSpeed(int... accelerations) {
    • currentSpeed = Arrays.stream(accelerations).sum();
    • }
    • public int getCurrentSpeed() {
    • return currentSpeed;
    • }
    • public boolean isWithinSpeedLimit() {
    • return currentSpeed <= currentRoad.speedLimit;
    • }
    • public int getTicketCost() {
    • if (currentSpeed>=currentRoad.speedLimit+10&&currentSpeed<currentRoad.speedLimit+19) {
    • return 100;
    • } else if (currentSpeed>=currentRoad.speedLimit+20&&currentSpeed<currentRoad.speedLimit+29) {
    • return 250;
    • } else if (currentSpeed>=currentRoad.speedLimit+30) {
    • return 500;
    • }
    • return 0;
    • }
    • }
    • final class Road {
    • int speedLimit;
    • public Road(int speedLimit) {
    • this.speedLimit = speedLimit;
    • }
    • }