N
N
NoMoneyException2016-07-29 21:30:55
Java
NoMoneyException, 2016-07-29 21:30:55

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;
    }
}

LinkedHashMap collection.
Or MB just write to ArrayList + come up with some other logic?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oleg Gamega, 2016-07-29
@gadfi

don't build big, you need a database

C
coden55, 2016-07-30
@coden55

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 question

Ask a Question

731 491 924 answers to any question