Ultra Geile Studenten Benutzer Oberfläche (UGSBO)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.7 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. package ugsbo.com.notenSpeicher;
  2. import java.security.MessageDigest;
  3. public class Noten {
  4. String Fach;
  5. int Note;
  6. double durchschnitt;
  7. Noten vorher;
  8. String ownHash;
  9. String previousHash;
  10. public Noten(String eingabeFach, int eingabeNote) {
  11. Fach = eingabeFach;
  12. Note = eingabeNote;
  13. durchschnitt = eingabeNote;
  14. vorher = null;
  15. previousHash = null;
  16. ownHash = createNewHash(eingabeFach);
  17. }
  18. public Noten(String eingabeFach, int eingabeNote, String previousHash, double durchschnitt, Noten vorher) {
  19. Fach = eingabeFach;
  20. Note = eingabeNote;
  21. ownHash = createNewHash(eingabeFach+previousHash);
  22. this.durchschnitt = (durchschnitt+eingabeNote)/2;
  23. this.vorher = vorher;
  24. this.previousHash = previousHash;
  25. }
  26. private String createNewHash(String input) {
  27. try {
  28. MessageDigest digest = MessageDigest.getInstance("SHA-256");
  29. //Applies sha256 to our input,
  30. byte[] hash = digest.digest(input.getBytes("UTF-8"));
  31. StringBuffer hexString = new StringBuffer(); // This will contain hash as hexidecimal
  32. for (int i = 0; i < hash.length; i++) {
  33. String hex = Integer.toHexString(0xff & hash[i]);
  34. if(hex.length() == 1) hexString.append('0');
  35. hexString.append(hex);
  36. }
  37. return hexString.toString();
  38. }
  39. catch(Exception e) {
  40. throw new RuntimeException(e);
  41. }
  42. }
  43. public String getFach() {
  44. return Fach;
  45. }
  46. public int getNote() {
  47. return Note;
  48. }
  49. public double getDurchschnitt() {
  50. return durchschnitt;
  51. }
  52. public Noten getVorher() {
  53. return vorher;
  54. }
  55. public String getOwnHash() {
  56. return ownHash;
  57. }
  58. }