Eingabe.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /**
  2. * @author (Jakob Kienegger)
  3. * @version (27.04.19)
  4. */
  5. import java.io.*;
  6. import java.util.*;
  7. public class Eingabe
  8. {
  9. private Element[][] matrix;
  10. private double multi = 1;
  11. private int n;
  12. private int m;
  13. public Eingabe()
  14. {
  15. n = 3;
  16. m = 4;
  17. }
  18. public void einlesen() throws IOException {
  19. //InputStreamReader isr = null;
  20. BufferedReader br = null;
  21. matrix = new Element[n][m];
  22. for(int i = 0; i < n; i++) {
  23. for(int j = 0; j < m; j++) {
  24. try {
  25. br = new BufferedReader(new InputStreamReader(System.in));
  26. System.out.print(+ i + "," + j + ": ");
  27. String eingabe = br.readLine();
  28. matrix[i][j] = new Element(Double.parseDouble(eingabe));
  29. } catch (IOException e) {
  30. e.printStackTrace();
  31. }
  32. }
  33. }
  34. if (br != null) {
  35. try {
  36. br.close();
  37. } catch (IOException e) {
  38. e.printStackTrace();
  39. }
  40. }
  41. }
  42. public double faktorCheck(Element zahl)
  43. {
  44. int value = (int) zahl.gibZahl();
  45. if(value != 1)
  46. {
  47. multi = 1/(zahl.gibZahl());
  48. zahl.multiZahl(multi);
  49. }
  50. return multi;
  51. }
  52. public double rechnen(Element zahl, double multi)
  53. {
  54. zahl.multiZahl(multi);
  55. return zahl.gibZahl();
  56. }
  57. public void zeilenFaktor(int a)
  58. {
  59. for(int i=0; i<n; i++)
  60. {
  61. multi = faktorCheck(matrix[i][a]);
  62. for(int j=1; j<m; j++)
  63. {
  64. matrix[i][j].multiZahl(multi);
  65. }
  66. }
  67. }
  68. public void ausgabe()
  69. {
  70. for(int j=0; j<n; j++)
  71. {
  72. for(int i=0; i<m; i++)
  73. {
  74. System.out.print( matrix[j][i].gibZahl() + ", ");
  75. }
  76. System.out.println("");
  77. }
  78. }
  79. public void gauss() throws IOException
  80. {
  81. //einlesen(m, n);
  82. zeilenFaktor(0);
  83. for(int j=1; j<3; j++)
  84. {
  85. for(int i=0; i<m; i++)
  86. {
  87. double a = matrix[0][i].gibZahl();
  88. double b = matrix[j][i].gibZahl();
  89. matrix[j][i].changeZahl(b-a);
  90. }
  91. }
  92. zeilenFaktor(1);
  93. for(int i=1; i<m; i++)
  94. {
  95. double a = matrix[1][i].gibZahl();
  96. double b = matrix[0][i].gibZahl();
  97. matrix[0][i].changeZahl(b-a);
  98. }
  99. for(int i=1; i<m; i++)
  100. {
  101. double a = matrix[1][i].gibZahl();
  102. double b = matrix[2][i].gibZahl();
  103. matrix[2][i].changeZahl(b-a);
  104. }
  105. zeilenFaktor(2);
  106. for(int j=0; j<2; j++)
  107. {
  108. for(int i=2; i<m; i++)
  109. {
  110. double a = matrix[2][i].gibZahl();
  111. double b = matrix[j][i].gibZahl();
  112. matrix[j][i].changeZahl(b-a);
  113. }
  114. }
  115. ausgabe();
  116. }
  117. public static void main (String[] args) {
  118. Eingabe a = new Eingabe();
  119. try {
  120. a.einlesen();
  121. a.gauss();
  122. } catch (IOException e) {
  123. e.printStackTrace();
  124. }
  125. //a.ausgabe();
  126. }
  127. /*
  128. */
  129. }