Mathematische Konsolenanwendung


Die Rezension über den Heutigen Programm wird euch in den folgenden Tagen präsentiert werden. Das Programm könnt ihr gerne für Lernzwecke ändern oder kopieren.

001 package java2enterprise;
002
003 import java.text.DecimalFormat;
004 import java.util.Scanner;
005
006 public class Main {
007
008      public static void main(String[] args) {
009
010      System.out.println("--------------");
011      System.out.println("PROGRAMM START");
012      System.out.println("--------------");
013      menue();
014
015 }
016
017 public static void ende() {
018      System.out.println("-------------");
019      System.out.println("PROGRAMM ENDE");
020      System.out.println("-------------");
021      System.exit(0);
022 }
023
024 public static double lineareGleichung(double a, double b) {
025
026
027      // Umwandlung in zwei Stellen nach dem Komma
028      DecimalFormat f = new DecimalFormat("#0.00");
029
030      // Ausgabe des Funktions
031      System.out.println("f(x) = "+f.format(a)+" * x + "+f.format(b));
032      System.out.println("f´(x) = "+f.format(a));
033      System.out.println("f´´(x) = 0");
034      System.out.println("f´´´(x) = 0");
035
036      // zurueck zum menue
037      menue();
038      return 0;
039 }
040
041 public static double quadratischeGleichung(double a, double b, double c) {
042
043      // Umwandlung in zwei Stellen nach dem Komma
044      DecimalFormat f = new DecimalFormat("#0.00");
045
046      // Ausgabe des Funktions
047      System.out.println("f(x) = "+f.format(a)+" * x^2 + "+f.format(b)+" * x "+f.format(c));
048      double wertdxa1 = (2 * a);
049      System.out.println("f´(x) = "+f.format(wertdxa1)+" x + "+f.format(b));
050      System.out.println("f´´(x) = "+f.format(wertdxa1));
051      System.out.println("f´´´(x) = 0");
052
053      // zurueck zum menue
054      menue();
055      return 0;
056 }
057
058 public static double qubischeGleichung(double a, double b, double c, double d) {
059
060      // Umwandlung in zwei Stellen nach dem Komma
061      DecimalFormat f = new DecimalFormat("#0.00");
062
063      // Ausgabe des Funktions
064      System.out.println("f(x) = "+f.format(a)+" * x^3 + "+f.format(b)+" * x ^2 "+f.format(c)+" * x                                                   "+f.format(d));
065      double wertdxa1 = (3 * a);
066      double wertdxb1 = (2 * b);
067      double wertdxa2 = (wertdxb1 * 2);
068      System.out.println("f´(x) = "+f.format(wertdxa1)+" x^2 + "+f.format(wertdxb1)+" * x                                                            +"+f.format(c));
069      System.out.println("f´´(x) = "+f.format(wertdxa2)+" x + "+f.format(wertdxb1));
070      System.out.println("f´´´(x) = "+f.format(wertdxa2));
071
072      // zurueck zum menue
073      menue();
074      return 0;
075
076 }
077 public static void menue() {
078      System.out.println("");
079      Scanner eingabe = new Scanner(System.in);
080      System.out.println("0=LINEARE FUNKTION");
081      System.out.println("1=QUADRATISCHE FUNKTION");
082      System.out.println("2=QUBISCHE FUNKTION");
083      System.out.println("3=ENDE");
084      byte ein = eingabe.nextByte();
085
086      if (ein == 0) {
087      System.out.println("GEBEN SIE EINE LINEARE FUNKTION IN FORM \n" + ">> f(x) = a * x + b << ein ");
089      // Eingabe des Parameters a
090      Scanner eingabeA = new Scanner(System.in);
091      System.out.println("GEBEN SIE DEN PARAMETER [a] EIN:");
092      double a = eingabeA.nextDouble();
093
094      // Eingabe der Konstante b
095      Scanner eingabeB = new Scanner(System.in);
096      System.out.println("GEBEN SIE DIE KONSTANTE [b] EIN:");
097      double b = eingabeB.nextDouble();
098
099      // Verbindung zu der Methode: lineareFunktion
100      lineareGleichung(a,b);
101 }
102      else if (ein == 1) {
103      System.out.println("GEBEN SIE EINE QUADRATISCHE FUNKTION IN FORM \n" +
104      ">> f(x) = a * x^2 + b * x + c << ein ");
105      // Eingabe des Parameters a
106      Scanner eingabeA = new Scanner(System.in);
107      System.out.println("GEBEN SIE DEN PARAMETER [a] EIN:");
108      double a = eingabeA.nextDouble();
109
110      // Eingabe des Parameters b
111      Scanner eingabeB = new Scanner(System.in);
112      System.out.println("GEBEN SIE DEN PARAMETER [b] EIN:");
113      double b = eingabeB.nextDouble();
114
115      // Eingabe der Konstante c
116      Scanner eingabeC = new Scanner(System.in);
117      System.out.println("GEBEN SIE DIE KONSTANTE [c] EIN:");
118      double c = eingabeC.nextDouble();
119
120      // Verbindung zu der Methode: quadratischeFunktion
121      quadratischeGleichung(a,b,c);
122
123 }
124      else if (ein == 2) {
125      System.out.println("GEBEN SIE EINE QUBISCHE FUNKTION IN FORM \n" +
126      ">> f(x) = a * x^3 + b * x^2 + c * x + d << ein ");
127      // Eingabe des Parameters a
128      Scanner eingabeA = new Scanner(System.in);
129      System.out.println("GEBEN SIE DEN PARAMETER [a] EIN:");
130      double a = eingabeA.nextDouble();
131
132      // Eingabe des Parameters b
133      Scanner eingabeB = new Scanner(System.in);
134      System.out.println("GEBEN SIE DEN PARAMETER [b] EIN:");
135      double b = eingabeB.nextDouble();
136
137      // Eingabe des Parameters c
138      Scanner eingabeC = new Scanner(System.in);
139      System.out.println("GEBEN SIE DEN PARAMETER [c] EIN:");
140      double c = eingabeC.nextDouble();
141
142      // Eingabe der Konstante d
143      Scanner eingabeD = new Scanner(System.in);
144      System.out.println("GEBEN SIE DIE KONSTANTE [d] EIN:");
145      double d = eingabeC.nextDouble();
146
147      // Verbindung zu der Methode: qubischeFunktion
148      qubischeGleichung(a,b,c,d);
149
150 }
151      else if (ein == 3) {
152      ende();
153 }
154      else {
155      System.out.println("UNGUELTIGE EINGABE");
156      menue();
157 }
158 }
159 }

Kommentare

Beliebte Posts aus diesem Blog

How can I transform a .jar file to a .bat file?

Raspberry Pi als echten Web- und Mailserver einsetzen (German)

Umrechnung von Grad Celsius nach Grad Fahrenheit