public class JedliksToyCar {
// ...
private JedliksToyCar() {
chargeInPercent = FULL_CHARGE_IN_PERCENT;
distance = 0;
}
public static JedliksToyCar buy() {
return new JedliksToyCar();
}
// ...
It is the best practice to declare a constructor private if we use public static method to create an instance. The current tests don’t allow students to follow the best practices. Fortunately, it can be fixed.
My initial thought is I think the exercise is fine as it currently is. What does the fix look like? Will it break existing solutions?
Some other thoughts:
The concept being taught here is classes. There is a separate constructors is also a separate concept that come later in the syllabus tree, so we’re not expecting students to write constructors just yet.
The students are asked to write the buy method so that they can practice creating an instance of the class. I don’t think there is any suggestion in the exercise that the method is intended to be the way to make an instance.