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(int dim_m, int dim_n) throws IOException {
  19. m = dim_m;
  20. n = dim_n;
  21. //InputStreamReader isr = null;
  22. BufferedReader br = null;
  23. matrix = new Element[m][n];
  24. for (int i = 0; i < n; i++) {
  25. for (int j = 0; j < m; j++) {
  26. try {
  27. br = new BufferedReader(new InputStreamReader(System.in));
  28. System.out.print(+i + "," + j + ": ");
  29. String eingabe = br.readLine();
  30. matrix[i][j] = new Element(Integer.parseInt(eingabe));
  31. } catch (IOException e) {
  32. e.printStackTrace();
  33. }
  34. }
  35. }
  36. if (br != null) {
  37. try {
  38. br.close();
  39. } catch (IOException e) {
  40. e.printStackTrace();
  41. }
  42. }
  43. }
  44. public double faktorCheck(Element zahl)
  45. {
  46. if(zahl.gibZahl() != 1)
  47. {
  48. multi = 1/(zahl.gibZahl());
  49. zahl.multiZahl(multi);
  50. }
  51. return multi;
  52. }
  53. public double rechnen(Element zahl, double multi)
  54. {
  55. zahl.multiZahl(multi);
  56. return zahl.gibZahl();
  57. }
  58. public void zeilenFaktor(int a)
  59. {
  60. for(int i=0; i<n; i++)
  61. {
  62. this.multi = faktorCheck(matrix[i][a]);
  63. for(int j=1; j<m; j++)
  64. {
  65. matrix[i][j].multiZahl(this.multi);
  66. }
  67. }
  68. }
  69. public void ausgabe()
  70. {
  71. for(int j=0; j<n; j++)
  72. {
  73. for(int i=0; i<m; i++)
  74. {
  75. System.out.print( matrix[j][i].gibZahl() + ", ");
  76. }
  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(2,2);
  121. } catch (IOException e) {
  122. e.printStackTrace();
  123. }
  124. a.ausgabe();
  125. }
  126. /*
  127. */
  128. }