As reported: Mastercard SDE-1 (Java/OOP) interview (2025), tech screening round: explain OOP to a five-year-old, then design a car system (models, engine, etc.) using design principles and design patterns, then print the prime numbers in a range.
Design the classes for a car system:
- A car has a model (for example a hatchback, a sedan, an SUV) and is built from parts such as an engine (petrol, diesel, electric), a transmission and optional features (sunroof, navigation, extra airbags).
- A car can be started, driven and stopped; the engine decides how it starts and what it consumes.
- New models, engine types and features should be addable without rewriting existing classes.
Cover the requirements you would agree on, the classes and how they relate, and which design principles (SOLID) and design patterns you use and why. Write the core code in Java.
Code runner format: two lines in LeetCode's design format: the method names and their arguments. The harness prints the list of return values (null for the constructor and stop). Implement CarSystem, which holds cars by id, with this practice scope:
- Models:
HATCHBACK(5 seats, base price 15000, enginesPETROL/ELECTRIC),SEDAN(5 seats, 22000, any engine),SUV(7 seats, 30000,DIESEL/ELECTRIC). Engines:PETROL(40 L tank, 7 L per 100 km, premium 0, starts with"petrol engine: spark ignition"),DIESEL(50 L, 5.5 L per 100 km, premium 1500,"diesel engine: glow plugs pre-heated, compression ignition"),ELECTRIC(60 kWh, 15 kWh per 100 km, premium 6000,"electric motor: battery self-check ok"). Tanks and batteries start full. build(carId, model, engine, transmission, color, featureNames, featurePrices)—""means "not given": transmission defaults toSINGLE_SPEEDfor electric cars andAUTOMATICotherwise, colour towhite. Returns"OK"(replacing any car with that id) or, checked in this order,"model and engine are required","<MODEL> is not offered with <ENGINE>","electric cars use a single-speed transmission"; a rejected build changes nothing.describe(carId)—"<color> <MODEL> (<ENGINE>, <TRANSMISSION>, <seats> seats)"followed by" + <feature>"per feature in order.price(carId)— base price + engine premium + feature prices.start(carId)— the engine's start message, or"already running".stop(carId).drive(carId, km)—"start the car first"when the car is off. Energy needed iskm * per100 / 100.0(computed in that order, as a double); if it is more than what is left, nothing changes, the alert"not enough energy for <km> km"is raised and the result is"not enough energy". Otherwise the energy and odometer are updated, the result is"ok", and if less than 10 % is left the alert"low battery"(electric) or"low fuel"is raised.energyLeft(carId)— percent left, rounded down.odometer(carId)— km driven.alerts(carId)— the car's alerts since the last call, oldest first.
Python uses snake_case (energy_left); Go uses Constructor() and exported names (Build, Drive, …).