Answer the question
In order to leave comments, you need to log in
Is it possible and necessary to use enum?
Hello. You need to create a collection where the Subject => Mark the key-value of the field will be stored. Since all students have the same subjects, I thought that we should use enum. Tell me if it's worth it, and how to implement it? Am I correct in my reasoning or is this a go * nocode?
public enum Subjects {
RUSSIAN("Russian: "),
ENGLISH("English: "),
PHYSICS("Physics: "),
INFORMATICS("Informatics: "),
HISTORY("History: ");
private String value;
private Subjects(String value) {
this.value = value;
}
public String getValue() {
return this.value;
}
}
Answer the question
In order to leave comments, you need to log in
I think it is possible without a database, it depends on the task.
I once did something similar, refused from the database. For storage, I serialized several classes when the program was closed and restored the state when the program started. It turned out quite convenient.
public enum Subjects {
RUSSIAN,
ENGLISH,
PHYSICS,
INFORMATICS,
HISTORY
}
hashmap.put(RUSSIAN,2);
hashmap.put(INFORMATICS,5)
for (Map.Entry<Subjects, Integer> entry : hashmap.entrySet()) {
System.out.println(entry.getKey().name() + ": " + entry.getValue());
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question