Eingabe.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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[m][n];
  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(Integer.parseInt(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. if(zahl.gibZahl() != 1)
  45. {
  46. multi = 1/(zahl.gibZahl());
  47. zahl.multiZahl(multi);
  48. }
  49. return multi;
  50. }
  51. public double rechnen(Element zahl, double multi)
  52. {
  53. zahl.multiZahl(multi);
  54. return zahl.gibZahl();
  55. }
  56. public void zeilenFaktor(int a)
  57. {
  58. for(int i=0; i<n; i++)
  59. {
  60. this.multi = faktorCheck(matrix[i][a]);
  61. for(int j=1; j<m; j++)
  62. {
  63. matrix[i][j].multiZahl(this.multi);
  64. }
  65. }
  66. }
  67. public void ausgabe()
  68. {
  69. for(int j=0; j<n; j++)
  70. {
  71. for(int i=0; i<m; i++)
  72. {
  73. System.out.print( matrix[j][i].gibZahl() + ", ");
  74. }
  75. }
  76. }
  77. public void gauss() throws IOException
  78. {
  79. //einlesen(m, n);
  80. zeilenFaktor(0);
  81. for(int j=1; j<3; j++)
  82. {
  83. for(int i=0; i<m; i++)
  84. {
  85. double a = matrix[0][i].gibZahl();
  86. double b = matrix[j][i].gibZahl();
  87. matrix[j][i].changeZahl(b-a);
  88. }
  89. }
  90. zeilenFaktor(1);
  91. for(int i=1; i<m; i++)
  92. {
  93. double a = matrix[1][i].gibZahl();
  94. double b = matrix[0][i].gibZahl();
  95. matrix[0][i].changeZahl(b-a);
  96. }
  97. for(int i=1; i<m; i++)
  98. {
  99. double a = matrix[1][i].gibZahl();
  100. double b = matrix[2][i].gibZahl();
  101. matrix[2][i].changeZahl(b-a);
  102. }
  103. zeilenFaktor(2);
  104. for(int j=0; j<2; j++)
  105. {
  106. for(int i=2; i<m; i++)
  107. {
  108. double a = matrix[2][i].gibZahl();
  109. double b = matrix[j][i].gibZahl();
  110. matrix[j][i].changeZahl(b-a);
  111. }
  112. }
  113. ausgabe();
  114. }
  115. public static void main (String[] args) {
  116. Eingabe a = new Eingabe();
  117. try {
  118. a.einlesen();
  119. a.gauss();
  120. } catch (IOException e) {
  121. e.printStackTrace();
  122. }
  123. a.ausgabe();
  124. }
  125. /*
  126. */
  127. }