-1

Im trying to make a marks storing program for my personal use, but i find problems when deciding how to store the marks. What i need is tsomething like this

Subject 1

----1(semesters)

------mark1

------mark2

------mark3

----2

------mark1

------mark2

----3

------mark1

I was thinking of using a HashMap or a local database, but the problem starts when some of the marks inside the same semester can be equal and i need to be able to delete or edit one of them.

BTW i feel more confident with java than other languages

2 Answers2

1

Give each of the marks a unique key. use a HashMap for that.

HashMap<String, String> marks = new HashMap<>();

marks.put("date_of_mark_given", mark);

Here is how to create unique keys deterministically based on dates.

final SimpleDateFormat sdf = new SimpleDateFormat("yyyy/mm/ddThh:MM:ss");
final UUID key = UUID.nameUUIDFromBytes(sdf.format(new Date()).getBytes());
final HashMap<UUID, String> marks = new HashMap<>();
marks.put(key, mark);

This is the best way to create keys that are not just plain String but can be recreated very easily and you never have to worry about collisions.

If the Date isn't unique enough, just add some other uniquely identifying information.

You should also make your mark into a real class, preferably and Enum.

Kyle Emmanuel
  • 2,193
  • 1
  • 15
  • 22
  • Instead of using the date, maybe i will generate an id. Cause two or more marks can be given the same day, but thnks for answering! – user3769416 Aug 16 '14 at 03:42
-1

Maybe MongoDB will be useful for you?

Laerion
  • 805
  • 2
  • 13
  • 18