Student Route Card with Inheritance
A school transport desk prints route cards for students who ride the morning shuttle. Every card needs the student's name and the route name, and the final printed format should read "Student Name - Route RouteName".
Your task is to model this with inheritance. A base class should represent the shared card owner data, while a child class should represent the student route card and produce the final label.
For example, if the input is "Ayu" and "Blue", the result should be "Student Ayu - Route Blue". If the input is "Bima" and "North", the result should be "Student Bima - Route North".
This challenge is not about difficult logic. It is about using a parent class for shared data and a child class for the student-specific card behavior. The returned string should always follow the same fixed format.
Example Input & Output
The route card format stays the same for every student.
The child class combines the inherited name with its own route field.
Any route name should appear in the same fixed label format.
Algorithm Flow

Solution Approach
This is a gentle inheritance exercise. The main OOP idea is that the child class should reuse data that already belongs in the parent class instead of redefining it from scratch.
A clean design is to create a base class such as RouteCard that stores the owner's name. Then a child class like StudentRouteCard can extend that base class, add the route field, and expose a method that returns the final printed label.
The relationship looks like this in Java terms:
The important inheritance step is extends RouteCard together with super(name). That tells Java that the student route card should reuse the parent class's name-handling logic instead of creating a separate disconnected field setup.
After construction, the child class can build the result with a method like getLabel() that uses both the inherited name and the child-specific route. That is the core learning goal here: parent and child classes each handle the part of the object they are responsible for.
The runtime is O(1). The value of the problem is not algorithmic complexity, but learning how inheritance lets one class build on another in a natural Java style.
Best Answers
class RouteCard {
protected String name;
public RouteCard(String name) {
this.name = name;
}
}
class StudentRouteCard extends RouteCard {
private String route;
public StudentRouteCard(String name, String route) {
super(name);
this.route = route;
}
public String getLabel() {
return String.format("Student %s - Route %s", name, route);
}
}
class Solution {
public static String makeRouteCard(String name, String route) {
return new StudentRouteCard(name, route).getLabel();
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
