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() + 30) {
            return 500;
          }
          
          if (currentSpeed >= currentRoad.speedLimit() + 20) {
            return 250;
          }
          
          if (currentSpeed >= currentRoad.speedLimit() + 10) {
            return 100;
          }
          
          return 0;
        }
    }
    
    record Road(int 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;
    • 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;
    • if (currentSpeed >= currentRoad.speedLimit() + 30) {
    • return 500;
    • }
    • if (currentSpeed >= currentRoad.speedLimit() + 20) {
    • return 250;
    • }
    • if (currentSpeed >= currentRoad.speedLimit() + 10) {
    • return 100;
    • }
    • return 0;
    • }
    • }
    • final class Road {
    • int speedLimit;
    • public Road(int speedLimit) {
    • this.speedLimit = speedLimit;
    • }
    • }
    • record Road(int speedLimit) { }