Eingabe.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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() throws IOException
  14. {
  15. n = 3;
  16. m = 4;
  17. }
  18. public void einlesen(int dim_m, int dim_n) throws IOException
  19. {
  20. m = dim_m;
  21. n = dim_n;
  22. for(int i=0; i<n; i++)
  23. {
  24. for(int j=0; j<m; j++)
  25. {
  26. InputStreamReader isr = new InputStreamReader(System.in);
  27. BufferedReader br = new BufferedReader(isr);
  28. System.out.print( + i + "," + j + ": ");
  29. String eingabe = br.readLine();
  30. matrix[j][i] = new Element(Double.parseDouble(eingabe));
  31. }
  32. }
  33. }
  34. public double faktorCheck(Element zahl)
  35. {
  36. if(zahl.gibZahl() != 1)
  37. {
  38. multi = 1/(zahl.gibZahl());
  39. zahl.multiZahl(multi);
  40. }
  41. return multi;
  42. }
  43. public double rechnen(Element zahl, double multi)
  44. {
  45. zahl.multiZahl(multi);
  46. return zahl.gibZahl();
  47. }
  48. public void zeilenFaktor(int a)
  49. {
  50. for(int i=0; i<n; i++)
  51. {
  52. this.multi = faktorCheck(matrix[i][a]);
  53. for(int j=1; j<m; j++)
  54. {
  55. matrix[i][j].multiZahl(this.multi);
  56. }
  57. }
  58. }
  59. public void ausgabe()
  60. {
  61. for(int j=0; j<n; j++)
  62. {
  63. for(int i=0; i<m; i++)
  64. {
  65. System.out.print( matrix[j][i].gibZahl() + ", ");
  66. }
  67. }
  68. }
  69. public void gauss() throws IOException
  70. {
  71. einlesen(m, n);
  72. zeilenFaktor(0);
  73. for(int j=1; j<3; j++)
  74. {
  75. for(int i=0; i<m; i++)
  76. {
  77. double a = matrix[0][i].gibZahl();
  78. double b = matrix[j][i].gibZahl();
  79. matrix[j][i].changeZahl(b-a);
  80. }
  81. }
  82. zeilenFaktor(1);
  83. for(int i=1; i<m; i++)
  84. {
  85. double a = matrix[1][i].gibZahl();
  86. double b = matrix[0][i].gibZahl();
  87. matrix[0][i].changeZahl(b-a);
  88. }
  89. for(int i=1; i<m; i++)
  90. {
  91. double a = matrix[1][i].gibZahl();
  92. double b = matrix[2][i].gibZahl();
  93. matrix[2][i].changeZahl(b-a);
  94. }
  95. zeilenFaktor(2);
  96. for(int j=0; j<2; j++)
  97. {
  98. for(int i=2; i<m; i++)
  99. {
  100. double a = matrix[2][i].gibZahl();
  101. double b = matrix[j][i].gibZahl();
  102. matrix[j][i].changeZahl(b-a);
  103. }
  104. }
  105. ausgabe();
  106. }
  107. /*
  108. */
  109. }