Eingabe.java.orig 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. <<<<<<< HEAD
  19. public void einlesen(int dim_m, int dim_n) throws IOException
  20. {
  21. m = dim_m;
  22. n = dim_n;
  23. for(int i=0; i<n; i++)
  24. {
  25. for(int j=0; j<m; j++)
  26. {
  27. InputStreamReader isr = new InputStreamReader(System.in);
  28. BufferedReader br = new BufferedReader(isr);
  29. System.out.print( + i + "," + j + ": ");
  30. String eingabe = br.readLine();
  31. matrix[j][i] = new Element(Double.parseDouble(eingabe));
  32. }
  33. =======
  34. public void einlesen() throws IOException {
  35. >>>>>>> dt
  36. //InputStreamReader isr = null;
  37. BufferedReader br = null;
  38. matrix = new Element[m][n];
  39. for (int i = 0; i < n; i++) {
  40. for (int j = 0; j < m; j++) {
  41. try {
  42. br = new BufferedReader(new InputStreamReader(System.in));
  43. System.out.print(+ i + "," + j + ": ");
  44. String eingabe = br.readLine();
  45. matrix[i][j] = new Element(Integer.parseInt(eingabe));
  46. } catch (IOException e) {
  47. e.printStackTrace();
  48. }
  49. }
  50. }
  51. if (br != null) {
  52. try {
  53. br.close();
  54. } catch (IOException e) {
  55. e.printStackTrace();
  56. }
  57. }
  58. }
  59. public double faktorCheck(Element zahl)
  60. {
  61. if(zahl.gibZahl() != 1)
  62. {
  63. multi = 1/(zahl.gibZahl());
  64. zahl.multiZahl(multi);
  65. }
  66. return multi;
  67. }
  68. public double rechnen(Element zahl, double multi)
  69. {
  70. zahl.multiZahl(multi);
  71. return zahl.gibZahl();
  72. }
  73. public void zeilenFaktor(int a)
  74. {
  75. for(int i=0; i<n; i++)
  76. {
  77. this.multi = faktorCheck(matrix[i][a]);
  78. for(int j=1; j<m; j++)
  79. {
  80. matrix[i][j].multiZahl(this.multi);
  81. }
  82. }
  83. }
  84. public void ausgabe()
  85. {
  86. for(int j=0; j<n; j++)
  87. {
  88. for(int i=0; i<m; i++)
  89. {
  90. System.out.print( matrix[j][i].gibZahl() + ", ");
  91. }
  92. }
  93. }
  94. public void gauss() throws IOException
  95. {
  96. //einlesen(m, n);
  97. zeilenFaktor(0);
  98. for(int j=1; j<3; j++)
  99. {
  100. for(int i=0; i<m; i++)
  101. {
  102. double a = matrix[0][i].gibZahl();
  103. double b = matrix[j][i].gibZahl();
  104. matrix[j][i].changeZahl(b-a);
  105. }
  106. }
  107. zeilenFaktor(1);
  108. for(int i=1; i<m; i++)
  109. {
  110. double a = matrix[1][i].gibZahl();
  111. double b = matrix[0][i].gibZahl();
  112. matrix[0][i].changeZahl(b-a);
  113. }
  114. for(int i=1; i<m; i++)
  115. {
  116. double a = matrix[1][i].gibZahl();
  117. double b = matrix[2][i].gibZahl();
  118. matrix[2][i].changeZahl(b-a);
  119. }
  120. zeilenFaktor(2);
  121. for(int j=0; j<2; j++)
  122. {
  123. for(int i=2; i<m; i++)
  124. {
  125. double a = matrix[2][i].gibZahl();
  126. double b = matrix[j][i].gibZahl();
  127. matrix[j][i].changeZahl(b-a);
  128. }
  129. }
  130. ausgabe();
  131. }
  132. public static void main (String[] args) {
  133. Eingabe a = new Eingabe();
  134. try {
  135. a.einlesen();
  136. a.gauss();
  137. } catch (IOException e) {
  138. e.printStackTrace();
  139. }
  140. a.ausgabe();
  141. }
  142. /*
  143. */
  144. }