From e54b51362812d1319fe0337c371d058f952c9a58 Mon Sep 17 00:00:00 2001 From: Luca Conte Date: Thu, 27 Oct 2022 22:16:50 +0200 Subject: [PATCH] add figur & project --- projekte/rechner/Rechner.class | Bin 0 -> 3078 bytes projekte/rechner/Rechner.java | 145 +++++++++++++++++++++++++++++++++ uebungen/h04_1/t01.class | Bin 0 -> 567 bytes uebungen/h04_1/t01.java | 13 +++ uebungen/h04_figur/Figur.class | Bin 0 -> 861 bytes uebungen/h04_figur/Figur.java | 39 +++++++++ 6 files changed, 197 insertions(+) create mode 100644 projekte/rechner/Rechner.class create mode 100644 projekte/rechner/Rechner.java create mode 100644 uebungen/h04_1/t01.class create mode 100644 uebungen/h04_1/t01.java create mode 100644 uebungen/h04_figur/Figur.class create mode 100644 uebungen/h04_figur/Figur.java diff --git a/projekte/rechner/Rechner.class b/projekte/rechner/Rechner.class new file mode 100644 index 0000000000000000000000000000000000000000..2ab5896c52a5e5412eb6c3191149543ddecdd1c2 GIT binary patch literal 3078 zcmai0Yit}>75?tb?9T3b_K~$GS=-qpO`K%?j+@}dcACbq<9fl)!%m%sG{xiHslE1k zce4*S=BXBgkodvRG=LftL01BPlnOak8bwI_0D+K@P=6p00-^puLc9b5tWfjaS*PCO z1#Hiqd(QpNch5QZoa_0~d-op#cnY8Np$Q+-(d(sf(gy{7a@Oy`fDfnewA7sTp%c%@ z;fxOr7?iWKau^De<5>?z-DfzFKVb-b*n^Mg7;~TTRCGR!;}xFnzsCX)hU zSinD&%@m4OrZ{D#OSZdW0@A3Hr5X1#f2t@bj+fFLhf_-e?o+8us(6}WtaVC28_Fha zf#6swW1lZA&e-|O)=ZijZP7|)1a`-+jm=w2R(IOU%yv%}^Qp}2fHd?^7Olj>xRrD8 zIwo{X>bNWr&fAOGC3`TRx0cVP?L|9N6wqVWhU2Z*=(9IfxRA5+R)#TXv7y$F3iu|o zrF_C3Ny&YU2|F>DvGZMWR|AJ}L|~WWL8+KZcTXm)3|DnLXJ86fB;a`iS0QN}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3HK;GKIYiN0E9ozag#NrNl8930bN3+r*xB_ zb6aknC5BOAUsI_44$P)d=N$x_LTz{8Z3=a-Lf6XB)NjA 0 && ((rechnung.charAt(i - 1) >= '0' && rechnung.charAt(i - 1) <= '9') || rechnung.charAt(i - 1) == '.' )) { + rechnung = rechnung.substring(0, i) + "*" + rechnung.substring(i); + i++; + numOperands++; + } + if (c == ')' && i < rechnung.length() - 1 && ((rechnung.charAt(i + 1) >= '0' && rechnung.charAt(i + 1) <= '9') || rechnung.charAt(i + 1) == '.')) { + rechnung = rechnung.substring(0, i + 1) + "*" + rechnung.substring(i + 1); + } + } + + double[] priorities = new double[numOperands]; + double[] operands = new double[numOperands]; + double[] terms = new double[numOperands + 1]; + + double priority = 0; + double highestPriority = 0; + + int operandIndex = 0; + + String currentNum = ""; + + for (int i = 0; i < rechnung.length(); i++) { + char c = rechnung.charAt(i); + + if (c == '(') { + priority += 2; + continue; + } + if (c == ')') { + priority -= 2; + continue; + } + + if ((c >= '0' && c <= '9') || c == '.') { + currentNum = currentNum + c; + continue; + } + + if (c == '-' && currentNum == "") { + currentNum = "-"; + continue; + } + + if (isOperand(c)) { + switch (c) { + case '+': + priorities[operandIndex] = priority; + if (priority > highestPriority) { + highestPriority = priority; + } + operands[operandIndex] = Rechner.Add; + break; + + case '-': + priorities[operandIndex] = priority; + if (priority > highestPriority) { + highestPriority = priority; + } + operands[operandIndex] = Rechner.Sub; + break; + + case '*': + priorities[operandIndex] = priority + 1; + if (priority + 1> highestPriority) { + highestPriority = priority + 1; + } + operands[operandIndex] = Rechner.Mul; + break; + + case '/': + priorities[operandIndex] = priority + 1; + if (priority + 1> highestPriority) { + highestPriority = priority + 1; + } + operands[operandIndex] = Rechner.Div; + break; + } + terms[operandIndex] = Double.parseDouble(currentNum); + currentNum = ""; + operandIndex++; + } + } + terms[operandIndex] = Double.parseDouble(currentNum); + + for (double prio = highestPriority; prio >= 0; prio--) { + for (int i = 0; i < operands.length; i++) { + if (priorities[i] == prio) { + if (operands[i] == Rechner.Add) { + terms[i + 1] = terms[i] + terms[i + 1]; + } else if (operands[i] == Rechner.Sub) { + terms[i + 1] = terms[i] - terms[i + 1]; + } else if (operands[i] == Rechner.Mul) { + terms[i + 1] = terms[i] * terms[i + 1]; + } else if (operands[i] == Rechner.Div) { + terms[i + 1] = terms[i] / terms[i + 1]; + } + terms = removeArrayElement(terms, i); + operands = removeArrayElement(operands, i); + priorities = removeArrayElement(priorities, i); + i--; + } + } + } + System.out.println(terms[0]); + } + + public static double[] removeArrayElement(double[] arr, int index) { + if (index >= arr.length || index < 0) return arr; + + double[] ret = new double[arr.length - 1]; + + for (int i = 0; i < arr.length; i++) { + if (i == index) continue; + + ret[i < index ? i : i -1] = arr[i]; + } + + return ret; + } + + public static boolean isOperand(char c) { + return c == '+' || c == '-' || c == '*' || c == '/'; + } +} diff --git a/uebungen/h04_1/t01.class b/uebungen/h04_1/t01.class new file mode 100644 index 0000000000000000000000000000000000000000..c9892cf39b3c4c3eb063aa52e1c6c83e44811c95 GIT binary patch literal 567 zcmZut%St0r5IxoDbhmA565ras9}q>1x>0;C1Yy9L5h89}b&@8uCLM_#!Mz{hJ`2~n zh~UEQzIvoXbb` zAS`dH!mfPe70-Tp=l}V3zSgK0{rx}{Tha2$k}7l10o%l=gE5Q?WYWZhgGo#&Gwomo zHkFVqNPmv`T{!iN(HAIxbrJbha%&AH`u}MPYPmxSiYUwXs+)q|xW`vmkUUo;R%O3m zMbG|F8<{b!5@HG_KT;hHq86a-WHd%E^vQ(>$Q>U7ht`NeMeIU1-->#J1TV0wZ@E?z z8~XOB<(8Vr+(YY0w4h&Wa{K;F*li+B&}|_ZV=oL^Fs_C9KWc~;4_TlJu%!tdX(Ta3 pKh9{5N*C!@nO|pqhwK!YgD~3Aqzyw}(btC1WnQU`zZy5qd;m8RZx{do literal 0 HcmV?d00001 diff --git a/uebungen/h04_1/t01.java b/uebungen/h04_1/t01.java new file mode 100644 index 0000000..0661c69 --- /dev/null +++ b/uebungen/h04_1/t01.java @@ -0,0 +1,13 @@ +public class t01 { + public static void main(String[] args) { + for (int i = 1; i <= 5; i++) { + for (int j = 1; j <= (5 - i); j++) { + System.out.print(" "); + } + for (int k = 1; k <= i; k++) { + System.out.print(i); + } + System.out.println(); + } + } +} diff --git a/uebungen/h04_figur/Figur.class b/uebungen/h04_figur/Figur.class new file mode 100644 index 0000000000000000000000000000000000000000..e1be109d670b1075b99c9f65a0436bb384ed5660 GIT binary patch literal 861 zcmZuvOK%cU7(EvTW|&Uff!dctYbjMJYEff!QED1BO-!ma!N)4QH8@AleN8QgcP zEh1Xm^?ZT3!sFe2_k~+(xqhQm2?Nh>Y%1bpC3I`g?zr7yeL9d`>4x`M5FVE)^1s~M zifkW9uh#VC4cQ2!e;@+^v(o7WHM!%d=H`yq=mi_9v4v^a78YRZIA`HJE(nNMIyNkn zaFOQ~3v-wkh?N;i5WW<_d0w^z5|I)+jza8J_hl^{gDNkdhqBE#>Gb$v_Sm)8Dg8+! z-S(!yOr$XmvqM)!ChI?8RaQOv-tv*-T&6fYKm%VKHrF(7OWXzbMDY{EdmaQbT$2$f zkira3@T^L|kQ(Ri9w8PlJGSu_4;=jsOj~#AeQ3_s2gEblMqpQPWGE<= z)ti6c$4kgE4~6It-celHh($K8(lyvLjszxXY7qvLm>h(KE6h`7j$5qUqsd3Cd4hR7 z<+x_avY`D$LZr9F57wmAoQ6TRsUBlR#(52!28;A}CL@$kWdnH5S= 4) ? (7 - i) : i; + + System.out.print("|"); + + repeatPrintString(" ",6 - len * 2); + + System.out.print("<>"); + + repeatPrintString(".", len * 4); + + System.out.print("<>"); + + repeatPrintString(" ",6 - len * 2); + + System.out.println("|"); + } + + zeichneBegrenzer(); + } + + public static void repeatPrintString(String s, int i) { + for (; i > 0; i--) { + System.out.print(s); + } + } + + public static void zeichneBegrenzer() { + System.out.print("#"); + repeatPrintString("=",16); + System.out.println("#"); + } +}