Design, and then simplify, an AvatarStore for a profile service.
The service has one concrete workflow:
.jpg or .png, ignoring case;2048 KB; andavatars/<fileName> on the local filesystem.Actual file I/O is outside this exercise. Returning and recording the destination path is enough.
The starter code predicts a much larger media platform. It has handler and storage-provider abstractions, accepts WebP files, and routes larger images to a cloud backend. None of that was requested. Refactor it to the design the product needs now:
AvatarStore() creates an empty store.String upload(String fileName, int sizeKb) checks file type before size and returns:"INVALID_TYPE" for any extension other than .jpg or .png;"TOO_LARGE" when a supported file is larger than 2048 KB; or"STORED: avatars/<fileName>" after a valid upload.int storedCount() returns the number of successful uploads.String lastPath() returns the most recently stored path, or "" before the first successful upload.Failed uploads do not change the count or the last path.
Input:
Output:
Explanation: Both files are supported and below the limit. The larger one still goes to the same local directory.
Input:
Output:
Explanation: WebP and cloud storage were guesses in the legacy design, not supported product features.
1 <= fileName.length <= 1000 <= sizeKb <= 10^6fileName contains only ASCII characters and has no path separators.100 calls will be made across all methods.The starter compiles but builds a plugin architecture around one local workflow. It also accepts an unsupported type and sends some files to an unrequested cloud backend.
Full marks when AvatarStore directly validates JPEG/PNG files and creates a local avatars path. Lose points heavily for WebP, video, cloud routing or other media and storage features not requested.
Full marks for one focused class and, at most, small private helpers. Lose points for retaining media-handler or storage-provider interfaces, registries, factories, adapters or backend selection logic.
Full marks when type is checked before size, only successful uploads increment the count, lastPath changes only on success, and exact statuses are returned. Lose points for accepting .jpeg or .webp, routing large files to cloud, or 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 AvatarStore() | null |
| upload("face.png", 500) | "STORED: avatars/face.png" |
| upload("team.JPG", 1500) | "STORED: avatars/team.JPG" |
| storedCount() | 2 |
| lastPath() | "avatars/team.JPG" |
Both supported image types use the same local directory, regardless of file size within the limit.
Run checks these cases. Submit also runs a larger hidden set.

