Design a Car class that remembers both its identity and its current speed as it is driven. The brand and model stay the same for the lifetime of the object, while the speed changes after every acceleration or braking operation.
Implement the Car class:
Car(String brand, String model) creates a car with the given brand and model. Every new car starts at 0 km/h.int accelerate(int amount) increases the current speed by amount, stores the result, and returns the new speed.int brake(int amount) decreases the current speed by amount, stores the result, and returns the new speed. If braking would make the speed negative, set it to 0 instead.int getSpeed() returns the car's current speed without changing it.String describe() returns the latest state in the exact format "<brand> <model> at <speed> km/h".All method calls operate on the same object. For example, accelerating by 20 and then by 15 produces a speed of 35, not 15. Braking by more than 35 then brings the car to a stop at 0.
Input:
Output:
Explanation: A new car is standing still, so it describes itself at 0 km/h. After accelerating by 20 it holds that speed and reports it.
Input:
Output:
Explanation: Speeding up twice adds to what was already there, reaching 70, and braking by 25 brings it down to 45.
1 <= brand.length, model.length <= 200 <= amount <= 100100 calls in total are made across all methods.Full marks when brand, model and speed are fields on the class, the constructor stores the two it is given, and speed starts at zero without being passed in. Lose points when speed is a parameter of the constructor, or when a value the class needs is passed into every method instead of being held.
Full marks when accelerate and brake adjust the car's own speed field and return the new value, so the car remembers what happened between calls. Lose points heavily when accelerate replaces the speed instead of adding to it, or when a method computes a number without storing it.
Full marks when braking below zero leaves the speed at zero and describe reads the current values rather than a copy made earlier. Lose points when the description is built from stale values or for printing to stdout.
Passing every test is not enough on its own. A submission is accepted only when the design also clears the bar.
| Call | Returns |
|---|---|
| new Car("Toyota", "Corolla") | null |
| describe() | "Toyota Corolla at 0 km/h" |
| accelerate(20) | 20 |
| getSpeed() | 20 |
| describe() | "Toyota Corolla at 20 km/h" |
A new car is standing still, so it describes itself at 0 km/h. After accelerating by 20 it holds that speed and reports it.
Run checks these cases. Submit also runs a larger hidden set.

