Student Badge Label
A school office is printing event badges for students. Each badge needs to show the student's name together with the grade level in a simple fixed format.
Your task is to use a small Student class and return the badge label in the form "Name - Grade X". The input provides the student's name and grade number, and the final label should combine them into one string.
For example, if the input is "Ayu" and 7, the answer should be "Ayu - Grade 7". If the input is "Bima" and 10, the answer should be "Bima - Grade 10".
This challenge is meant to be a gentle Java OOP exercise. Instead of building the output directly in one loose line, the idea is to store the student's data inside an object and let that object provide the label through one of its own methods.
Example Input & Output
Two pieces of student data become one readable label.
The student's name and grade are combined into the badge format.
The same class pattern works for any grade number.
Algorithm Flow

Solution Approach
This problem is small, but it shows one of the core ideas of object-oriented programming in Java: related data and behavior can live together inside the same class.
Here, the data is the student's name and grade. The behavior is the ability to produce a badge label from that data. That makes a Student class a natural fit.
A clean design is to give Student a constructor that stores the two input values, then add a method such as getBadgeLabel() that returns the final formatted string. The outer solution method can create a Student object and ask it for that label.
The structure looks like this:
Then the solution method simply creates the object and returns the method result. That keeps the formatting logic attached to the class that owns the data, which is the main OOP lesson here.
You could build the string directly without a class, but that would miss the point of the exercise. The goal is to practice using a constructor, instance fields, and an instance method in a way that still feels easy and practical.
The runtime is constant, O(1), because only one object and one short string are created. The real value of the problem is the class design pattern, not algorithmic complexity.
Best Answers
class Student {
private String name;
private int grade;
public Student(String name, int grade) {
this.name = name;
this.grade = grade;
}
public String getBadgeLabel() {
return String.format("%s - Grade %d", name, grade);
}
}
class Solution {
public static String makeBadgeLabel(String name, int grade) {
return new Student(name, grade).getBadgeLabel();
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
