/* ================================================================================ = Autor: Mario SCHNEPF = MatrklNr: e0225056 = E-Mail: ma_s@gmx.at / e0225056@student.tuwien.ac.at = Datum: 15. Jänner 2003 ================================================================================ = abstract void doAbleitung() throws EprogException; = ==> siehe Term.java.doAbleitung() = ------------------------------------------------------------------------------ = abstract void checkFormatierung() throws EprogException; = ==> siehe Term.java.doAbleitung() = ------------------------------------------------------------------------------ = abstract String erzeugeString (); = ==> siehe Term.java.doAbleitung() ================================================================================ */ package symbdiff; import eprog.*; class euler extends Term { // ANFANG: Variablen deklarieren ============================================= public int Koeffizient = +1; public int Zahl = 1; // ENDE: Variablen deklarieren =============================================== // ANFANG: Konstruktor ======================================================= public euler (String Temp) { Eingabe = Temp; } // ENDE: Konstruktor ========================================================= // ANFANG: checkFormatierung ================================================= public void checkFormatierung() throws EprogException { // Vorzeichen überprüfen (wenn "-" ==> negativ - sonst in jedem Fall + // anschließend Vorzeichen aus dem Eingabestring löschen if (Eingabe.charAt(0) == '-') { Koeffizient = -1; Eingabe = Eingabe.substring(1); } else { Koeffizient = +1; if (Eingabe.charAt(0) == '+') Eingabe = Eingabe.substring(1); } // EULER aus dem Eingabestring entfernen if (Eingabe.substring(0,1).equals(Global.EULER)) { Eingabe = Eingabe.substring(1); } else throw new EprogException ("EULER: e im Term nicht gefunden"); // überprüfen ob der String != 0 ist (also nur EULER enthält) if (Eingabe.length() == 0) throw new EprogException("EULER: keine Variable gefunden"); // KLAMMERAUF und KLAMMERZU aus dem String entfernen // jetzt darf der Eingabe-String nur noch 3 oder 4 Zeichen lang sein // Format: "()" oder "()" ==> andernfalls FEHLER if ((Eingabe.substring(0,1).equals(Global.KLAMMERAUF)) && (Eingabe.substring(Eingabe.length()-1).equals(Global.KLAMMERZU))) { Eingabe = Eingabe.substring(1,Eingabe.length()-1); } else throw new EprogException ("EULER: Keine Klammern"); // Eingabe-String darf jetzt nur noch 1 oder 2 lang sein // Format "" oder "" if (Eingabe.length() == 2) { x = Eingabe.substring(1); Zahl = erzeugeInt(Eingabe.substring(0,1)); if (Zahl == -1) throw new EprogException("EULER: Zahl"); } else if (Eingabe.length() == 1) x = Eingabe.substring(0); else throw new EprogException ("EULER: falsches Format"); // neue Variable gefunden ==> Fehler if (Global.X.indexOf(x) == -1) throw new EprogException ("EULER: falsche Variable"); } // ENDE: checkFormatierung =================================================== // ANFANG: doAbleitung ======================================================= public void doAbleitung() throws EprogException { // nach Global.V ableiten if (Global.V == null) Global.V = x; else if (!(Global.V.equals(x)) && (x != null)) throw new EprogException ("EULER: falsche Variable gefunden: "); Koeffizient = Koeffizient * Zahl; } // ENDE: doAbleitung ========================================================= // ANFANG: erzeugeString ===================================================== public String erzeugeString() { String Ausgabe = ""; // wenn Koeffizient gleich 0 ==> es muss nichts ausgeben werden if (Koeffizient == 0) return ""; // überprüfen welches Vorzeichen und welcher Koeffizient im Ausgabestring // ausgegeben werden muss if (Koeffizient > 1) Ausgabe = "+" + Koeffizient; else if (Koeffizient == 1) Ausgabe = "+"; else Ausgabe = Integer.toString(Koeffizient); Ausgabe += Global.EULER + Global.KLAMMERAUF; if (Zahl != 1) Ausgabe += Zahl; Ausgabe += x + Global.KLAMMERZU; return Ausgabe; } // ENDE: erzeugeString ======================================================= }