Eingabe.java 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. public Element[][] matrix;
  10. private double multi = 1;
  11. private int zeilenZahl;
  12. private int spaltenZahl;
  13. private double zahl;
  14. public Eingabe()
  15. {
  16. zeilenZahl = 3;
  17. spaltenZahl = 4;
  18. }
  19. public void einlesen() throws IOException {
  20. //InputStreamReader isr = null;
  21. BufferedReader br = null;
  22. matrix = new Element[zeilenZahl][spaltenZahl];
  23. for(int i = 0; i < zeilenZahl; i++) {
  24. for(int j = 0; j < spaltenZahl; j++) {
  25. try {
  26. br = new BufferedReader(new InputStreamReader(System.in));
  27. System.out.print(+ i + "," + j + ": ");
  28. String eingabe = br.readLine();
  29. matrix[i][j] = new Element(Integer.parseInt(eingabe));
  30. } catch (IOException e) {
  31. e.printStackTrace();
  32. }
  33. }
  34. }
  35. if (br != null) {
  36. try {
  37. br.close();
  38. } catch (IOException e) {
  39. e.printStackTrace();
  40. }
  41. }
  42. }
  43. public void ausgabe()
  44. {
  45. for(int j=0; j<zeilenZahl; j++)
  46. {
  47. for(int i=0; i<spaltenZahl; i++)
  48. {
  49. System.out.print( matrix[j][i].gibZahl() + ", ");
  50. }
  51. System.out.println("");
  52. }
  53. }
  54. public void zeileMulti(int zeile)
  55. {
  56. for(int i=0; i<spaltenZahl; i++)
  57. {
  58. matrix[zeile][i].multiZahl(this.multi);
  59. }
  60. }
  61. public void zeilenAddition(int zeileStatic, int zeileChange)
  62. {
  63. for(int i=0; i<spaltenZahl; i++)
  64. {
  65. this.zahl = matrix[zeileChange][i].gibZahl() - matrix[zeileStatic][i].gibZahl();
  66. matrix[zeileChange][i].changeZahl(this.zahl);
  67. }
  68. }
  69. public void gaussAlgorithmus(int zeilenZahl, int spaltenZahl)
  70. {
  71. for(int i=0; i<zeilenZahl; i++)
  72. {
  73. this.multi = 1/(matrix[i][i].gibZahl());
  74. for(int k=0; k<zeilenZahl; k++)
  75. {
  76. zeileMulti(k);
  77. }
  78. for(int j=0; j<i | j>i; j++)
  79. {
  80. zeilenAddition(i, j);
  81. }
  82. }
  83. }
  84. public static void main (String[] args) {
  85. Eingabe a = new Eingabe();
  86. //Gauss b = new Gauss(3, 4);
  87. try {
  88. a.einlesen();
  89. a.gaussAlgorithmus(3, 4);
  90. a.ausgabe();
  91. } catch (IOException e) {
  92. e.printStackTrace();
  93. }
  94. }
  95. /*
  96. */
  97. }