Warm‑up: Map Requirements to OOP Pillars (with answer)
Warm‑up (with answer): You are building a small "Ticketing" system. Choose and justify the best OOP feature for each requirement: 1) Hide internal state (e.g., password/token) 2) Allow multiple payment types (UPI/Card/Cash) with same API 3) Reuse common logic for all ticket types (Bus/Train/Flight) 4) Customize behavior per ticket type without changing caller Write short reasoning + print sample output lines. ✅ Warm-up answer should mention: Encapsulation, Abstraction (interface), Inheritance, Polymorphism.
import java.util.*; // Collections
public class Main { // entry class
// ✅ TODO: Student must implement only this method
static void explainOOP() {
// TODO:
// - Print 4 lines, each mapping requirement -> OOP concept
// - Use clear words: Encapsulation/Abstraction/Inheritance/Polymorphism
throw new UnsupportedOperationException("TODO");
}
public static void main(String[] args) { // program entry
explainOOP(); // print explanation
}
}
Warm‑up Answer (Concept Map)
Mapping: 1) Hide internal state => Encapsulation (private fields + controlled access) 2) Multiple payment types => Abstraction (Payment interface) + Polymorphism 3) Reuse common logic => Inheritance (BaseTicket with shared fields/methods) 4) Customize behavior => Polymorphism (override methods; call via base type)
System.out.println("1) Hide token => Encapsulation (private fields + controlled access).");
System.out.println("2) UPI/Card/Cash => Abstraction (Payment interface).");
System.out.println("3) Common ticket logic => Inheritance (BaseTicket).");
System.out.println("4) Different behavior => Polymorphism (override + dynamic dispatch).");