Class declarations and object modeling: Correct Solution
Translate the specification below into an idiomatic Java class definition.
(In this context, "idiomatic" means following the common style and conventions of the language.)
-
One kind of thing that exists in our model is a Chlem.
-
All Chlems share a single THECRAP, which is a string. It is a constant. Its value is "ge". Other classes cannot see its value.
Solution
public class Chlem {
public static String THECRAP = "ge";
public Chlem() {
}
}
Things to check in your solution:
- Is every
public and private modifier correct?
- Are the correct items
static?
- Are the correct items
final?
- Are all the variable types and method return types correct?
- Are the class members in the correct order? It should be: (1) static variables, (2) instance variables, (3) constructors, (4) methods.
- Do members have the correct capitalization?
Acceptable variations in the solution:
- It is OK if you initialized non-static variables in the constructor instead of in the declaration. (Ask your instructor if you aren’t clear what this means.) Note that static variables must be initialized in the declaration.
- It is OK if you used a slightly different but equivalent form of an expression, such as
+= 1 instead of ++.
Related puzzles: