blikk info infothek forum galerie sitemap

Zinsenberechnung in Java

zur Aufgabenstellung

importjava.io.BufferedReader;

importjava.io.IOException;

importjava.io.InputStreamReader;

 

public classZinsenberechnung {

 

public static void main(String[]args) {

 

      boolean again = false;

 

      BufferedReadereingabe = new BufferedReader(new InputStreamReader(

                        System.in));

      do {

      try {

            System.out.println("Waswillst du berechnen? n"

                             + "(1)Zinsen n" + "(2) Zinseszinsen n"

                             + "(3)Beenden ");

            int a = Integer.parseInt(eingabe.readLine());

 

            if (a == 1 || a ==2) {

                  try {

                        System.out.println("Gebensie Ihr Startkapital

 ein!");

                        double k =Double.parseDouble(eingabe.readLine());

                        System.out.println("GebenSie den Zinsensatz

 ein!");

                        double p =Double.parseDouble(eingabe.readLine());

                        System.out.println("GebenSie die Zeit in Jahre

 ein!");

                        int t = Integer.parseInt(eingabe.readLine());

 

                        if (a == 1) {

                             double kn = k *(1 + p / 100 * t);

                             System.out.println("DasEndkapital beträgt: "

 + kn);

                        }

                        if (a == 2) {

                              double kn = Math.pow((1 + p/ 100), t) * 100;

                             System.out.println("DasEndkapital beträgt: "

 + kn);

                        }

                  }catch (IOException e) {

                        System.out.println("Error 3");

                    }

            } else if (a == 3) {

                  System.exit(1);

                  } else {

                        System.out.println("FalscheEingabe!");

                        }

            try {

                  System.out.println("Willstdu das Programm

 wiederholen?(y/n)");

                  String weiter = (eingabe.readLine());

                  if (weiter.compareTo("y") == 0) {

                        again= true;

                        }else {

                             again= false;

                        }

            } catch(IOException e) {

                  System.out.println("Error 3");

            }

 

      } catch(IOException e) {

            System.out.println("Error 3");

      }

} while (again == true);

      }

}...

Michael Di Domenico


nach oben